-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFoodRepository.php
68 lines (61 loc) · 1.54 KB
/
FoodRepository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace App\Repositories;
use App\Models\Food;
use Illuminate\Container\Container as Application;
use InfyOm\Generator\Common\BaseRepository;
use Prettus\Repository\Contracts\CacheableInterface;
use Prettus\Repository\Traits\CacheableRepository;
/**
* Class FoodRepository
* @package App\Repositories
* @version August 29, 2019, 9:38 pm UTC
*
* @method Food findWithoutFail($id, $columns = ['*'])
* @method Food find($id, $columns = ['*'])
* @method Food first($columns = ['*'])
*/
class FoodRepository extends BaseRepository implements CacheableInterface
{
use CacheableRepository;
/**
* @var array
*/
protected $fieldSearchable = [
'name',
'price',
'discount_price',
'description',
'ingredients',
'weight',
'package_items_count',
'unit',
'featured',
'restaurant_id',
'category_id'
];
/**
* Configure the Model
**/
public function model()
{
return Food::class;
}
/**
* get my foods
**/
public function myFoods()
{
return Food::join("user_restaurants", "user_restaurants.restaurant_id", "=", "foods.restaurant_id")
->where('user_restaurants.user_id', auth()->id())->get();
}
public function groupedByRestaurants()
{
$foods = [];
foreach ($this->all() as $model) {
if(!empty($model->restaurant)){
$foods[$model->restaurant->name][$model->id] = $model->name;
}
}
return $foods;
}
}