Trying to get my head around the logic for the following.
I have 3 images and two static functions
. I believe it's possible to make one function but lack the knowledge of how to achieve this and putting the issue into words is hard, so google is of no help currently.
1 of the 3 images is outside of the foreach loop in the view, so in the model I created two public static functions. This is my issue, is there a better way to do this then use 2 functions?
Table in the database is "images" and consists of following:
- id
- image
- page
- list
Currently the Model looks like this:
class Images extends Eloquent {
public static function indexPageTL()
{
$images = DB::table('images')
->where('page', 'index')
->whereBetween('list', array(0,1))
->orderBy('list', 'asc')
->get();
return $images;
}
public static function indexPageMR()
{
$images = DB::table('images')
->where('page', 'index')
->whereBetween('list', array(2,4))
->orderBy('list', 'asc')
->get();
return $images;
}
}
As you can see in the model I am using an array to select the items I need, so as to separate them (hence the two functions). I pass this to my services to better combine the data:
namespace Services;
use Images;
class IndexService
{
public function indexData()
{
$data = array(
'images' => Images::indexPageMR(),
'imagesTL' => Images::indexPageTL()
);
return $data;
}
}
Then in my controller:
use Services\IndexService;
class IndexController extends BaseController
{
public function index() {
return View::make('index', with(new IndexService())->indexData());
}
}
Finally in the view:
@foreach($imagesTL as $fetch)
<img src="{{ $fetch->image }}" class="img-responsive">
@endforeach
//then further down the page I call the indexPageMR()
@foreach($imagesMR as $fetch)
<img src="{{ $fetch->image }}" class="img-responsive">
@endforeach
Question is essentially, do I need 2 separate public static functions
for this or can I combine them, if i can combine them how do I do it?
Apologies if this is unclear, as I said it's hard to put into words.