$types = ['Fruit', 'Vegetable', 'Drink'];
$consume = Modal::whereIn('type', $types)->get(); // or simply ::all() if you want all of them
$fruits = $consume->filter(function ($item) {
return $item->type == 'Fruit';
}
// the same for other types, then pass these collections to your view
May 22, 2015
4
Level 1
[HELP] Efficent way to get data from DB?
I have a table that's probably going to contain a lot of data, some of this data is categorized by type.
Say for example, 3 records is a type of Fruit, 10 records is a type of Vegetable, and 100 records is a type of Drink.
I want to seperate these types into their own HTML table, without having to call Modal::where('type', 'Fruit') for each of these tables.
Is there an efficent way to sort of so this using just one Modal class call?
So something along the lines of:
$consume = new Modal;
return View::make('consume')->withConsume($consume);
And consume.blade.php would do:
@foreach($consume->where('type', 'Vegetable') as $c)
@endforeach
I should probably point out that I am using Laravel 4.2 for this.
Level 53
1 like
Please or to participate in this conversation.