@@ -7,67 +7,67 @@ |
||
7 | 7 | |
8 | 8 | class Handler extends ExceptionHandler |
9 | 9 | { |
10 | - /** |
|
11 | - * A list of the exception types that are not reported. |
|
12 | - * |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - protected $dontReport = [ |
|
16 | - \League\OAuth2\Server\Exception\OAuthServerException::class, |
|
17 | - ]; |
|
10 | + /** |
|
11 | + * A list of the exception types that are not reported. |
|
12 | + * |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + protected $dontReport = [ |
|
16 | + \League\OAuth2\Server\Exception\OAuthServerException::class, |
|
17 | + ]; |
|
18 | 18 | |
19 | - /** |
|
20 | - * A list of the inputs that are never flashed for validation exceptions. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $dontFlash = [ |
|
25 | - 'password', |
|
26 | - 'password_confirmation', |
|
27 | - ]; |
|
19 | + /** |
|
20 | + * A list of the inputs that are never flashed for validation exceptions. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $dontFlash = [ |
|
25 | + 'password', |
|
26 | + 'password_confirmation', |
|
27 | + ]; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Report or log an exception. |
|
31 | - * |
|
32 | - * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
|
33 | - * |
|
34 | - * @param \Exception $exception |
|
35 | - * @return void |
|
36 | - */ |
|
37 | - public function report(Exception $exception) |
|
38 | - { |
|
39 | - parent::report($exception); |
|
40 | - } |
|
29 | + /** |
|
30 | + * Report or log an exception. |
|
31 | + * |
|
32 | + * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
|
33 | + * |
|
34 | + * @param \Exception $exception |
|
35 | + * @return void |
|
36 | + */ |
|
37 | + public function report(Exception $exception) |
|
38 | + { |
|
39 | + parent::report($exception); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Render an exception into an HTTP response. |
|
44 | - * |
|
45 | - * @param \Illuminate\Http\Request $request |
|
46 | - * @param \Exception $exception |
|
47 | - * @return \Illuminate\Http\Response |
|
48 | - */ |
|
49 | - public function render($request, Exception $exception) |
|
50 | - { |
|
51 | - if ($request->wantsJson()) { |
|
52 | - if ($exception instanceof \Illuminate\Auth\AuthenticationException) { |
|
53 | - \ErrorHandler::unAuthorized(); |
|
54 | - } |
|
55 | - if ($exception instanceof \Illuminate\Database\QueryException) { |
|
56 | - \ErrorHandler::dbQueryError(); |
|
57 | - } elseif ($exception instanceof \predis\connection\connectionexception) { |
|
58 | - \ErrorHandler::redisNotRunning(); |
|
59 | - } elseif ($exception instanceof \GuzzleHttp\Exception\ClientException) { |
|
60 | - \ErrorHandler::connectionError(); |
|
61 | - } elseif ($exception instanceof \Symfony\Component\HttpKernel\Exception\HttpException) { |
|
62 | - $errors = $exception->getStatusCode() === 404 ? 'not found' : $exception->getMessage(); |
|
63 | - return \Response::json(['errors' => [$errors]], $exception->getStatusCode()); |
|
64 | - } elseif ($exception instanceof \Illuminate\Validation\ValidationException) { |
|
65 | - return \Response::json(['errors' => $exception->errors()], 422); |
|
66 | - } elseif (! $exception instanceof \Symfony\Component\ErrorHandler\Error\FatalError) { |
|
67 | - return parent::render($request, $exception); |
|
68 | - } |
|
69 | - } |
|
42 | + /** |
|
43 | + * Render an exception into an HTTP response. |
|
44 | + * |
|
45 | + * @param \Illuminate\Http\Request $request |
|
46 | + * @param \Exception $exception |
|
47 | + * @return \Illuminate\Http\Response |
|
48 | + */ |
|
49 | + public function render($request, Exception $exception) |
|
50 | + { |
|
51 | + if ($request->wantsJson()) { |
|
52 | + if ($exception instanceof \Illuminate\Auth\AuthenticationException) { |
|
53 | + \ErrorHandler::unAuthorized(); |
|
54 | + } |
|
55 | + if ($exception instanceof \Illuminate\Database\QueryException) { |
|
56 | + \ErrorHandler::dbQueryError(); |
|
57 | + } elseif ($exception instanceof \predis\connection\connectionexception) { |
|
58 | + \ErrorHandler::redisNotRunning(); |
|
59 | + } elseif ($exception instanceof \GuzzleHttp\Exception\ClientException) { |
|
60 | + \ErrorHandler::connectionError(); |
|
61 | + } elseif ($exception instanceof \Symfony\Component\HttpKernel\Exception\HttpException) { |
|
62 | + $errors = $exception->getStatusCode() === 404 ? 'not found' : $exception->getMessage(); |
|
63 | + return \Response::json(['errors' => [$errors]], $exception->getStatusCode()); |
|
64 | + } elseif ($exception instanceof \Illuminate\Validation\ValidationException) { |
|
65 | + return \Response::json(['errors' => $exception->errors()], 422); |
|
66 | + } elseif (! $exception instanceof \Symfony\Component\ErrorHandler\Error\FatalError) { |
|
67 | + return parent::render($request, $exception); |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | - return parent::render($request, $exception); |
|
72 | - } |
|
71 | + return parent::render($request, $exception); |
|
72 | + } |
|
73 | 73 | } |
@@ -63,7 +63,7 @@ |
||
63 | 63 | return \Response::json(['errors' => [$errors]], $exception->getStatusCode()); |
64 | 64 | } elseif ($exception instanceof \Illuminate\Validation\ValidationException) { |
65 | 65 | return \Response::json(['errors' => $exception->errors()], 422); |
66 | - } elseif (! $exception instanceof \Symfony\Component\ErrorHandler\Error\FatalError) { |
|
66 | + } elseif ( ! $exception instanceof \Symfony\Component\ErrorHandler\Error\FatalError) { |
|
67 | 67 | return parent::render($request, $exception); |
68 | 68 | } |
69 | 69 | } |
@@ -6,37 +6,37 @@ |
||
6 | 6 | class Setting extends Model |
7 | 7 | { |
8 | 8 | |
9 | - use SoftDeletes; |
|
10 | - protected $table = 'settings'; |
|
11 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
12 | - protected $hidden = ['deleted_at']; |
|
13 | - protected $guarded = ['id', 'key']; |
|
14 | - protected $fillable = ['name', 'value']; |
|
15 | - public $searchable = ['name', 'value', 'key']; |
|
9 | + use SoftDeletes; |
|
10 | + protected $table = 'settings'; |
|
11 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
12 | + protected $hidden = ['deleted_at']; |
|
13 | + protected $guarded = ['id', 'key']; |
|
14 | + protected $fillable = ['name', 'value']; |
|
15 | + public $searchable = ['name', 'value', 'key']; |
|
16 | 16 | |
17 | - public function getCreatedAtAttribute($value) |
|
18 | - { |
|
19 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
20 | - } |
|
17 | + public function getCreatedAtAttribute($value) |
|
18 | + { |
|
19 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
20 | + } |
|
21 | 21 | |
22 | - public function getUpdatedAtAttribute($value) |
|
23 | - { |
|
24 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
25 | - } |
|
22 | + public function getUpdatedAtAttribute($value) |
|
23 | + { |
|
24 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
25 | + } |
|
26 | 26 | |
27 | - public function getDeletedAtAttribute($value) |
|
28 | - { |
|
29 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
30 | - } |
|
27 | + public function getDeletedAtAttribute($value) |
|
28 | + { |
|
29 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
30 | + } |
|
31 | 31 | |
32 | - public function newCollection(array $models = []) |
|
33 | - { |
|
34 | - return parent::newCollection($models)->keyBy('key'); |
|
35 | - } |
|
32 | + public function newCollection(array $models = []) |
|
33 | + { |
|
34 | + return parent::newCollection($models)->keyBy('key'); |
|
35 | + } |
|
36 | 36 | |
37 | - public static function boot() |
|
38 | - { |
|
39 | - parent::boot(); |
|
40 | - Setting::observe(\App::make('App\Modules\Core\ModelObservers\SettingsObserver')); |
|
41 | - } |
|
37 | + public static function boot() |
|
38 | + { |
|
39 | + parent::boot(); |
|
40 | + Setting::observe(\App::make('App\Modules\Core\ModelObservers\SettingsObserver')); |
|
41 | + } |
|
42 | 42 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @param array $relations |
36 | 36 | * @param string $sortBy |
37 | - * @param boolean $desc |
|
37 | + * @param integer $desc |
|
38 | 38 | * @param array $columns |
39 | 39 | * @return collection |
40 | 40 | */ |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @param integer $perPage |
53 | 53 | * @param array $relations |
54 | 54 | * @param string $sortBy |
55 | - * @param boolean $desc |
|
55 | + * @param integer $desc |
|
56 | 56 | * @param array $columns |
57 | 57 | * @return collection |
58 | 58 | */ |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @param integer $perPage |
155 | 155 | * @param array $relations |
156 | 156 | * @param string $sortBy |
157 | - * @param boolean $desc |
|
157 | + * @param integer $desc |
|
158 | 158 | * @param array $columns |
159 | 159 | * @return collection |
160 | 160 | */ |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @param integer $perPage |
173 | 173 | * @param array $relations |
174 | 174 | * @param string $sortBy |
175 | - * @param boolean $desc |
|
175 | + * @param integer $desc |
|
176 | 176 | * @param array $columns |
177 | 177 | * @return collection |
178 | 178 | */ |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * Save the given model to the storage. |
189 | 189 | * |
190 | 190 | * @param array $data |
191 | - * @return mixed |
|
191 | + * @return boolean |
|
192 | 192 | */ |
193 | 193 | public function save(array $data) |
194 | 194 | { |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | * @param array $conditions array of conditions |
478 | 478 | * @param array $relations |
479 | 479 | * @param string $sortBy |
480 | - * @param boolean $desc |
|
480 | + * @param integer $desc |
|
481 | 481 | * @param array $columns |
482 | 482 | * @return collection |
483 | 483 | */ |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | * @param array $conditions array of conditions |
510 | 510 | * @param integer $perPage |
511 | 511 | * @param string $sortBy |
512 | - * @param boolean $desc |
|
512 | + * @param integer $desc |
|
513 | 513 | * @param array $columns |
514 | 514 | * @return collection |
515 | 515 | */ |
@@ -6,625 +6,625 @@ |
||
6 | 6 | |
7 | 7 | abstract class BaseRepository implements BaseRepositoryInterface |
8 | 8 | { |
9 | - /** |
|
10 | - * The model implementation. |
|
11 | - * |
|
12 | - * @var object |
|
13 | - */ |
|
14 | - public $model; |
|
9 | + /** |
|
10 | + * The model implementation. |
|
11 | + * |
|
12 | + * @var object |
|
13 | + */ |
|
14 | + public $model; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Init new object. |
|
18 | - * |
|
19 | - * @var mixed model |
|
20 | - * @return void |
|
21 | - */ |
|
22 | - public function __construct($model) |
|
23 | - { |
|
24 | - $this->model = $model; |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * Fetch records with relations based on the given params. |
|
29 | - * |
|
30 | - * @param string $relations |
|
31 | - * @param array $conditions |
|
32 | - * @param integer $perPage |
|
33 | - * @param string $sortBy |
|
34 | - * @param boolean $desc |
|
35 | - * @return collection |
|
36 | - */ |
|
37 | - public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true) |
|
38 | - { |
|
39 | - unset($conditions['page']); |
|
40 | - unset($conditions['perPage']); |
|
41 | - unset($conditions['sortBy']); |
|
42 | - unset($conditions['sort']); |
|
43 | - unset($conditions['page']); |
|
44 | - |
|
45 | - if (count($conditions)) { |
|
46 | - return $this->paginateBy(['and' => $conditions], $perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true); |
|
47 | - } |
|
48 | - |
|
49 | - return $this->paginate($perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Fetch all records with relations from the storage. |
|
54 | - * |
|
55 | - * @param array $relations |
|
56 | - * @param string $sortBy |
|
57 | - * @param boolean $desc |
|
58 | - * @param array $columns |
|
59 | - * @return collection |
|
60 | - */ |
|
61 | - public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
62 | - { |
|
63 | - $sort = $desc ? 'desc' : 'asc'; |
|
64 | - return $this->model->with($relations)->orderBy($sortBy, $sort)->get($columns); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Fetch all records with relations from storage in pages |
|
69 | - * that matche the given query. |
|
70 | - * |
|
71 | - * @param string $query |
|
72 | - * @param integer $perPage |
|
73 | - * @param array $relations |
|
74 | - * @param string $sortBy |
|
75 | - * @param boolean $desc |
|
76 | - * @param array $columns |
|
77 | - * @return collection |
|
78 | - */ |
|
79 | - public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
80 | - { |
|
81 | - $model = $this->model->with($relations); |
|
82 | - $conditionColumns = $this->model->searchable; |
|
83 | - $sort = $desc ? 'desc' : 'asc'; |
|
84 | - |
|
85 | - /** |
|
86 | - * Construct the select conditions for the model. |
|
87 | - */ |
|
88 | - $model->where(function ($q) use ($query, $conditionColumns, $relations) { |
|
89 | - |
|
90 | - if (count($conditionColumns)) { |
|
91 | - $column = 'LOWER('.array_shift($conditionColumns).')'; |
|
92 | - if (Str::contains($column, '->')) { |
|
93 | - $column = $this->wrapJsonSelector($column); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Use the first element in the model columns to construct the first condition. |
|
98 | - */ |
|
99 | - $q->where(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Loop through the rest of the columns to construct or where conditions. |
|
104 | - */ |
|
105 | - foreach ($conditionColumns as $column) { |
|
106 | - $column = 'LOWER('.$column.')'; |
|
107 | - if (Str::contains($column, '->')) { |
|
108 | - $column = $this->wrapJsonSelector($column); |
|
109 | - } |
|
110 | - |
|
111 | - $q->orWhere(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Loop through the model relations. |
|
116 | - */ |
|
117 | - foreach ($relations as $relation) { |
|
118 | - /** |
|
119 | - * Remove the sub relation if exists. |
|
120 | - */ |
|
121 | - $relation = explode('.', $relation)[0]; |
|
122 | - |
|
123 | - /** |
|
124 | - * Try to fetch the relation repository from the core. |
|
125 | - */ |
|
126 | - if (\Core::$relation()) { |
|
127 | - /** |
|
128 | - * Construct the relation condition. |
|
129 | - */ |
|
130 | - $q->orWhereHas($relation, function ($subModel) use ($query, $relation) { |
|
131 | - |
|
132 | - $subModel->where(function ($q) use ($query, $relation) { |
|
133 | - |
|
134 | - /** |
|
135 | - * Get columns of the relation. |
|
136 | - */ |
|
137 | - $subConditionColumns = \Core::$relation()->model->searchable; |
|
138 | - |
|
139 | - if (count($subConditionColumns)) { |
|
140 | - $column = 'LOWER('.array_shift($subConditionColumns).')'; |
|
141 | - if (Str::contains($column, '->')) { |
|
142 | - $column = $this->wrapJsonSelector($column); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Use the first element in the relation model columns to construct the first condition. |
|
147 | - */ |
|
148 | - $q->where(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Loop through the rest of the columns to construct or where conditions. |
|
153 | - */ |
|
154 | - foreach ($subConditionColumns as $subConditionColumn) { |
|
155 | - $column = 'LOWER('.$subConditionColumn.')'; |
|
156 | - if (Str::contains($column, '->')) { |
|
157 | - $column = $this->wrapJsonSelector($column); |
|
158 | - } |
|
16 | + /** |
|
17 | + * Init new object. |
|
18 | + * |
|
19 | + * @var mixed model |
|
20 | + * @return void |
|
21 | + */ |
|
22 | + public function __construct($model) |
|
23 | + { |
|
24 | + $this->model = $model; |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * Fetch records with relations based on the given params. |
|
29 | + * |
|
30 | + * @param string $relations |
|
31 | + * @param array $conditions |
|
32 | + * @param integer $perPage |
|
33 | + * @param string $sortBy |
|
34 | + * @param boolean $desc |
|
35 | + * @return collection |
|
36 | + */ |
|
37 | + public function list($relations = [], $conditions = false, $perPage = 15, $sortBy = 'created_at', $desc = true) |
|
38 | + { |
|
39 | + unset($conditions['page']); |
|
40 | + unset($conditions['perPage']); |
|
41 | + unset($conditions['sortBy']); |
|
42 | + unset($conditions['sort']); |
|
43 | + unset($conditions['page']); |
|
44 | + |
|
45 | + if (count($conditions)) { |
|
46 | + return $this->paginateBy(['and' => $conditions], $perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true); |
|
47 | + } |
|
48 | + |
|
49 | + return $this->paginate($perPage ?? 15, $relations, $sortBy ?? 'created_at', $desc ?? true); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Fetch all records with relations from the storage. |
|
54 | + * |
|
55 | + * @param array $relations |
|
56 | + * @param string $sortBy |
|
57 | + * @param boolean $desc |
|
58 | + * @param array $columns |
|
59 | + * @return collection |
|
60 | + */ |
|
61 | + public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
62 | + { |
|
63 | + $sort = $desc ? 'desc' : 'asc'; |
|
64 | + return $this->model->with($relations)->orderBy($sortBy, $sort)->get($columns); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Fetch all records with relations from storage in pages |
|
69 | + * that matche the given query. |
|
70 | + * |
|
71 | + * @param string $query |
|
72 | + * @param integer $perPage |
|
73 | + * @param array $relations |
|
74 | + * @param string $sortBy |
|
75 | + * @param boolean $desc |
|
76 | + * @param array $columns |
|
77 | + * @return collection |
|
78 | + */ |
|
79 | + public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
80 | + { |
|
81 | + $model = $this->model->with($relations); |
|
82 | + $conditionColumns = $this->model->searchable; |
|
83 | + $sort = $desc ? 'desc' : 'asc'; |
|
84 | + |
|
85 | + /** |
|
86 | + * Construct the select conditions for the model. |
|
87 | + */ |
|
88 | + $model->where(function ($q) use ($query, $conditionColumns, $relations) { |
|
89 | + |
|
90 | + if (count($conditionColumns)) { |
|
91 | + $column = 'LOWER('.array_shift($conditionColumns).')'; |
|
92 | + if (Str::contains($column, '->')) { |
|
93 | + $column = $this->wrapJsonSelector($column); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Use the first element in the model columns to construct the first condition. |
|
98 | + */ |
|
99 | + $q->where(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Loop through the rest of the columns to construct or where conditions. |
|
104 | + */ |
|
105 | + foreach ($conditionColumns as $column) { |
|
106 | + $column = 'LOWER('.$column.')'; |
|
107 | + if (Str::contains($column, '->')) { |
|
108 | + $column = $this->wrapJsonSelector($column); |
|
109 | + } |
|
110 | + |
|
111 | + $q->orWhere(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Loop through the model relations. |
|
116 | + */ |
|
117 | + foreach ($relations as $relation) { |
|
118 | + /** |
|
119 | + * Remove the sub relation if exists. |
|
120 | + */ |
|
121 | + $relation = explode('.', $relation)[0]; |
|
122 | + |
|
123 | + /** |
|
124 | + * Try to fetch the relation repository from the core. |
|
125 | + */ |
|
126 | + if (\Core::$relation()) { |
|
127 | + /** |
|
128 | + * Construct the relation condition. |
|
129 | + */ |
|
130 | + $q->orWhereHas($relation, function ($subModel) use ($query, $relation) { |
|
131 | + |
|
132 | + $subModel->where(function ($q) use ($query, $relation) { |
|
133 | + |
|
134 | + /** |
|
135 | + * Get columns of the relation. |
|
136 | + */ |
|
137 | + $subConditionColumns = \Core::$relation()->model->searchable; |
|
138 | + |
|
139 | + if (count($subConditionColumns)) { |
|
140 | + $column = 'LOWER('.array_shift($subConditionColumns).')'; |
|
141 | + if (Str::contains($column, '->')) { |
|
142 | + $column = $this->wrapJsonSelector($column); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Use the first element in the relation model columns to construct the first condition. |
|
147 | + */ |
|
148 | + $q->where(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Loop through the rest of the columns to construct or where conditions. |
|
153 | + */ |
|
154 | + foreach ($subConditionColumns as $subConditionColumn) { |
|
155 | + $column = 'LOWER('.$subConditionColumn.')'; |
|
156 | + if (Str::contains($column, '->')) { |
|
157 | + $column = $this->wrapJsonSelector($column); |
|
158 | + } |
|
159 | 159 | |
160 | - $q->orWhere(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
161 | - } |
|
162 | - }); |
|
163 | - }); |
|
164 | - } |
|
165 | - } |
|
166 | - }); |
|
160 | + $q->orWhere(\DB::raw($column), 'LIKE', '%'.strtolower($query).'%'); |
|
161 | + } |
|
162 | + }); |
|
163 | + }); |
|
164 | + } |
|
165 | + } |
|
166 | + }); |
|
167 | 167 | |
168 | - return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
169 | - } |
|
168 | + return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Fetch all records with relations from storage in pages. |
|
173 | - * |
|
174 | - * @param integer $perPage |
|
175 | - * @param array $relations |
|
176 | - * @param string $sortBy |
|
177 | - * @param boolean $desc |
|
178 | - * @param array $columns |
|
179 | - * @return collection |
|
180 | - */ |
|
181 | - public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
182 | - { |
|
183 | - $sort = $desc ? 'desc' : 'asc'; |
|
184 | - return $this->model->with($relations)->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Fetch all records with relations based on |
|
189 | - * the given condition from storage in pages. |
|
190 | - * |
|
191 | - * @param array $conditions array of conditions |
|
192 | - * @param integer $perPage |
|
193 | - * @param array $relations |
|
194 | - * @param string $sortBy |
|
195 | - * @param boolean $desc |
|
196 | - * @param array $columns |
|
197 | - * @return collection |
|
198 | - */ |
|
199 | - public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
200 | - { |
|
201 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
202 | - $sort = $desc ? 'desc' : 'asc'; |
|
203 | - return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
204 | - } |
|
171 | + /** |
|
172 | + * Fetch all records with relations from storage in pages. |
|
173 | + * |
|
174 | + * @param integer $perPage |
|
175 | + * @param array $relations |
|
176 | + * @param string $sortBy |
|
177 | + * @param boolean $desc |
|
178 | + * @param array $columns |
|
179 | + * @return collection |
|
180 | + */ |
|
181 | + public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
182 | + { |
|
183 | + $sort = $desc ? 'desc' : 'asc'; |
|
184 | + return $this->model->with($relations)->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Fetch all records with relations based on |
|
189 | + * the given condition from storage in pages. |
|
190 | + * |
|
191 | + * @param array $conditions array of conditions |
|
192 | + * @param integer $perPage |
|
193 | + * @param array $relations |
|
194 | + * @param string $sortBy |
|
195 | + * @param boolean $desc |
|
196 | + * @param array $columns |
|
197 | + * @return collection |
|
198 | + */ |
|
199 | + public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
200 | + { |
|
201 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
202 | + $sort = $desc ? 'desc' : 'asc'; |
|
203 | + return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
204 | + } |
|
205 | 205 | |
206 | - /** |
|
207 | - * Save the given model to the storage. |
|
208 | - * |
|
209 | - * @param array $data |
|
210 | - * @return mixed |
|
211 | - */ |
|
212 | - public function save(array $data) |
|
213 | - { |
|
214 | - \Session::put('locale', 'all'); |
|
215 | - $model = false; |
|
216 | - $modelClass = $this->model; |
|
217 | - $relations = []; |
|
218 | - |
|
219 | - \DB::transaction(function () use (&$model, &$relations, $data, $modelClass) { |
|
220 | - /** |
|
221 | - * If the id is present in the data then select the model for updating, |
|
222 | - * else create new model. |
|
223 | - * @var array |
|
224 | - */ |
|
225 | - $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
|
226 | - if (! $model) { |
|
227 | - \ErrorHandler::notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Construct the model object with the given data, |
|
232 | - * and if there is a relation add it to relations array, |
|
233 | - * then save the model. |
|
234 | - */ |
|
235 | - foreach ($data as $key => $value) { |
|
236 | - /** |
|
237 | - * If the attribute is a relation. |
|
238 | - */ |
|
239 | - $relation = \Str::camel($key); |
|
240 | - if (method_exists($model, $relation) && \Core::$relation()) { |
|
241 | - /** |
|
242 | - * Check if the relation is a collection. |
|
243 | - */ |
|
244 | - if (class_basename($model->$relation) == 'Collection') { |
|
245 | - /** |
|
246 | - * If the relation has no value then marke the relation data |
|
247 | - * related to the model to be deleted. |
|
248 | - */ |
|
249 | - if (! $value || ! count($value)) { |
|
250 | - $relations[$relation] = 'delete'; |
|
251 | - } |
|
252 | - } |
|
253 | - if (is_array($value)) { |
|
254 | - /** |
|
255 | - * Loop through the relation data. |
|
256 | - */ |
|
257 | - foreach ($value as $attr => $val) { |
|
258 | - /** |
|
259 | - * Get the relation model. |
|
260 | - */ |
|
261 | - $relationBaseModel = \Core::$relation()->model; |
|
262 | - |
|
263 | - /** |
|
264 | - * Check if the relation is a collection. |
|
265 | - */ |
|
266 | - if (class_basename($model->$relation) == 'Collection') { |
|
267 | - /** |
|
268 | - * If the id is present in the data then select the relation model for updating, |
|
269 | - * else create new model. |
|
270 | - */ |
|
271 | - $relationModel = Arr::has($val, 'id') ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
|
272 | - |
|
273 | - /** |
|
274 | - * If model doesn't exists. |
|
275 | - */ |
|
276 | - if (! $relationModel) { |
|
277 | - \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Loop through the relation attributes. |
|
282 | - */ |
|
283 | - foreach ($val as $attr => $val) { |
|
284 | - /** |
|
285 | - * Prevent the sub relations or attributes not in the fillable. |
|
286 | - */ |
|
287 | - if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) { |
|
288 | - $relationModel->$attr = $val; |
|
289 | - } |
|
290 | - } |
|
291 | - |
|
292 | - $relations[$relation][] = $relationModel; |
|
293 | - } else { |
|
294 | - /** |
|
295 | - * Prevent the sub relations. |
|
296 | - */ |
|
297 | - if (gettype($val) !== 'object' && gettype($val) !== 'array') { |
|
298 | - /** |
|
299 | - * If the id is present in the data then select the relation model for updating, |
|
300 | - * else create new model. |
|
301 | - */ |
|
302 | - $relationModel = Arr::has($value, 'id') ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
|
303 | - |
|
304 | - /** |
|
305 | - * If model doesn't exists. |
|
306 | - */ |
|
307 | - if (! $relationModel) { |
|
308 | - \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
309 | - } |
|
310 | - |
|
311 | - foreach ($value as $relationAttribute => $relationValue) { |
|
312 | - /** |
|
313 | - * Prevent attributes not in the fillable. |
|
314 | - */ |
|
315 | - if (array_search($relationAttribute, $relationModel->getFillable(), true) !== false) { |
|
316 | - $relationModel->$relationAttribute = $relationValue; |
|
317 | - } |
|
318 | - } |
|
319 | - |
|
320 | - $relations[$relation] = $relationModel; |
|
321 | - } |
|
322 | - } |
|
323 | - } |
|
324 | - } |
|
325 | - } elseif (array_search($key, $model->getFillable(), true) !== false) { |
|
326 | - /** |
|
327 | - * If the attribute isn't a relation and prevent attributes not in the fillable. |
|
328 | - */ |
|
329 | - $model->$key = $value; |
|
330 | - } |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Loop through the relations array. |
|
335 | - */ |
|
336 | - foreach ($relations as $key => $value) { |
|
337 | - /** |
|
338 | - * If the relation is marked for delete then delete it. |
|
339 | - */ |
|
340 | - if ($value == 'delete' && $model->$key()->count()) { |
|
341 | - $model->$key()->delete(); |
|
342 | - } elseif (gettype($value) == 'array') { |
|
343 | - /** |
|
344 | - * Save the model. |
|
345 | - */ |
|
346 | - $model->save(); |
|
347 | - $ids = []; |
|
348 | - |
|
349 | - /** |
|
350 | - * Loop through the relations. |
|
351 | - */ |
|
352 | - foreach ($value as $val) { |
|
353 | - switch (class_basename($model->$key())) { |
|
354 | - /** |
|
355 | - * If the relation is one to many then update it's foreign key with |
|
356 | - * the model id and save it then add its id to ids array to delete all |
|
357 | - * relations who's id isn't in the ids array. |
|
358 | - */ |
|
359 | - case 'HasMany': |
|
360 | - $foreignKeyName = $model->$key()->getForeignKeyName(); |
|
361 | - $val->$foreignKeyName = $model->id; |
|
362 | - $val->save(); |
|
363 | - $ids[] = $val->id; |
|
364 | - break; |
|
365 | - |
|
366 | - /** |
|
367 | - * If the relation is many to many then add it's id to the ids array to |
|
368 | - * attache these ids to the model. |
|
369 | - */ |
|
370 | - case 'BelongsToMany': |
|
371 | - $val->save(); |
|
372 | - $ids[] = $val->id; |
|
373 | - break; |
|
374 | - } |
|
375 | - } |
|
376 | - switch (class_basename($model->$key())) { |
|
377 | - /** |
|
378 | - * If the relation is one to many then delete all |
|
379 | - * relations who's id isn't in the ids array. |
|
380 | - */ |
|
381 | - case 'HasMany': |
|
382 | - $model->$key()->whereNotIn('id', $ids)->delete(); |
|
383 | - break; |
|
384 | - |
|
385 | - /** |
|
386 | - * If the relation is many to many then |
|
387 | - * detach the previous data and attach |
|
388 | - * the ids array to the model. |
|
389 | - */ |
|
390 | - case 'BelongsToMany': |
|
391 | - $model->$key()->detach(); |
|
392 | - $model->$key()->attach($ids); |
|
393 | - break; |
|
394 | - } |
|
395 | - } else { |
|
396 | - switch (class_basename($model->$key())) { |
|
397 | - /** |
|
398 | - * If the relation is one to one. |
|
399 | - */ |
|
400 | - case 'HasOne': |
|
401 | - /** |
|
402 | - * Save the model. |
|
403 | - */ |
|
404 | - $model->save(); |
|
405 | - $foreignKeyName = $model->$key()->getForeignKeyName(); |
|
406 | - $value->$foreignKeyName = $model->id; |
|
407 | - $value->save(); |
|
408 | - break; |
|
409 | - case 'BelongsTo': |
|
410 | - /** |
|
411 | - * Save the model. |
|
412 | - */ |
|
413 | - $value->save(); |
|
414 | - $model->$key()->associate($value); |
|
415 | - break; |
|
416 | - } |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - /** |
|
421 | - * Save the model. |
|
422 | - */ |
|
423 | - $model->save(); |
|
424 | - }); |
|
206 | + /** |
|
207 | + * Save the given model to the storage. |
|
208 | + * |
|
209 | + * @param array $data |
|
210 | + * @return mixed |
|
211 | + */ |
|
212 | + public function save(array $data) |
|
213 | + { |
|
214 | + \Session::put('locale', 'all'); |
|
215 | + $model = false; |
|
216 | + $modelClass = $this->model; |
|
217 | + $relations = []; |
|
218 | + |
|
219 | + \DB::transaction(function () use (&$model, &$relations, $data, $modelClass) { |
|
220 | + /** |
|
221 | + * If the id is present in the data then select the model for updating, |
|
222 | + * else create new model. |
|
223 | + * @var array |
|
224 | + */ |
|
225 | + $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
|
226 | + if (! $model) { |
|
227 | + \ErrorHandler::notFound(class_basename($modelClass).' with id : '.$data['id']); |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Construct the model object with the given data, |
|
232 | + * and if there is a relation add it to relations array, |
|
233 | + * then save the model. |
|
234 | + */ |
|
235 | + foreach ($data as $key => $value) { |
|
236 | + /** |
|
237 | + * If the attribute is a relation. |
|
238 | + */ |
|
239 | + $relation = \Str::camel($key); |
|
240 | + if (method_exists($model, $relation) && \Core::$relation()) { |
|
241 | + /** |
|
242 | + * Check if the relation is a collection. |
|
243 | + */ |
|
244 | + if (class_basename($model->$relation) == 'Collection') { |
|
245 | + /** |
|
246 | + * If the relation has no value then marke the relation data |
|
247 | + * related to the model to be deleted. |
|
248 | + */ |
|
249 | + if (! $value || ! count($value)) { |
|
250 | + $relations[$relation] = 'delete'; |
|
251 | + } |
|
252 | + } |
|
253 | + if (is_array($value)) { |
|
254 | + /** |
|
255 | + * Loop through the relation data. |
|
256 | + */ |
|
257 | + foreach ($value as $attr => $val) { |
|
258 | + /** |
|
259 | + * Get the relation model. |
|
260 | + */ |
|
261 | + $relationBaseModel = \Core::$relation()->model; |
|
262 | + |
|
263 | + /** |
|
264 | + * Check if the relation is a collection. |
|
265 | + */ |
|
266 | + if (class_basename($model->$relation) == 'Collection') { |
|
267 | + /** |
|
268 | + * If the id is present in the data then select the relation model for updating, |
|
269 | + * else create new model. |
|
270 | + */ |
|
271 | + $relationModel = Arr::has($val, 'id') ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel; |
|
272 | + |
|
273 | + /** |
|
274 | + * If model doesn't exists. |
|
275 | + */ |
|
276 | + if (! $relationModel) { |
|
277 | + \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Loop through the relation attributes. |
|
282 | + */ |
|
283 | + foreach ($val as $attr => $val) { |
|
284 | + /** |
|
285 | + * Prevent the sub relations or attributes not in the fillable. |
|
286 | + */ |
|
287 | + if (gettype($val) !== 'object' && gettype($val) !== 'array' && array_search($attr, $relationModel->getFillable(), true) !== false) { |
|
288 | + $relationModel->$attr = $val; |
|
289 | + } |
|
290 | + } |
|
291 | + |
|
292 | + $relations[$relation][] = $relationModel; |
|
293 | + } else { |
|
294 | + /** |
|
295 | + * Prevent the sub relations. |
|
296 | + */ |
|
297 | + if (gettype($val) !== 'object' && gettype($val) !== 'array') { |
|
298 | + /** |
|
299 | + * If the id is present in the data then select the relation model for updating, |
|
300 | + * else create new model. |
|
301 | + */ |
|
302 | + $relationModel = Arr::has($value, 'id') ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel; |
|
303 | + |
|
304 | + /** |
|
305 | + * If model doesn't exists. |
|
306 | + */ |
|
307 | + if (! $relationModel) { |
|
308 | + \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
|
309 | + } |
|
310 | + |
|
311 | + foreach ($value as $relationAttribute => $relationValue) { |
|
312 | + /** |
|
313 | + * Prevent attributes not in the fillable. |
|
314 | + */ |
|
315 | + if (array_search($relationAttribute, $relationModel->getFillable(), true) !== false) { |
|
316 | + $relationModel->$relationAttribute = $relationValue; |
|
317 | + } |
|
318 | + } |
|
319 | + |
|
320 | + $relations[$relation] = $relationModel; |
|
321 | + } |
|
322 | + } |
|
323 | + } |
|
324 | + } |
|
325 | + } elseif (array_search($key, $model->getFillable(), true) !== false) { |
|
326 | + /** |
|
327 | + * If the attribute isn't a relation and prevent attributes not in the fillable. |
|
328 | + */ |
|
329 | + $model->$key = $value; |
|
330 | + } |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Loop through the relations array. |
|
335 | + */ |
|
336 | + foreach ($relations as $key => $value) { |
|
337 | + /** |
|
338 | + * If the relation is marked for delete then delete it. |
|
339 | + */ |
|
340 | + if ($value == 'delete' && $model->$key()->count()) { |
|
341 | + $model->$key()->delete(); |
|
342 | + } elseif (gettype($value) == 'array') { |
|
343 | + /** |
|
344 | + * Save the model. |
|
345 | + */ |
|
346 | + $model->save(); |
|
347 | + $ids = []; |
|
348 | + |
|
349 | + /** |
|
350 | + * Loop through the relations. |
|
351 | + */ |
|
352 | + foreach ($value as $val) { |
|
353 | + switch (class_basename($model->$key())) { |
|
354 | + /** |
|
355 | + * If the relation is one to many then update it's foreign key with |
|
356 | + * the model id and save it then add its id to ids array to delete all |
|
357 | + * relations who's id isn't in the ids array. |
|
358 | + */ |
|
359 | + case 'HasMany': |
|
360 | + $foreignKeyName = $model->$key()->getForeignKeyName(); |
|
361 | + $val->$foreignKeyName = $model->id; |
|
362 | + $val->save(); |
|
363 | + $ids[] = $val->id; |
|
364 | + break; |
|
365 | + |
|
366 | + /** |
|
367 | + * If the relation is many to many then add it's id to the ids array to |
|
368 | + * attache these ids to the model. |
|
369 | + */ |
|
370 | + case 'BelongsToMany': |
|
371 | + $val->save(); |
|
372 | + $ids[] = $val->id; |
|
373 | + break; |
|
374 | + } |
|
375 | + } |
|
376 | + switch (class_basename($model->$key())) { |
|
377 | + /** |
|
378 | + * If the relation is one to many then delete all |
|
379 | + * relations who's id isn't in the ids array. |
|
380 | + */ |
|
381 | + case 'HasMany': |
|
382 | + $model->$key()->whereNotIn('id', $ids)->delete(); |
|
383 | + break; |
|
384 | + |
|
385 | + /** |
|
386 | + * If the relation is many to many then |
|
387 | + * detach the previous data and attach |
|
388 | + * the ids array to the model. |
|
389 | + */ |
|
390 | + case 'BelongsToMany': |
|
391 | + $model->$key()->detach(); |
|
392 | + $model->$key()->attach($ids); |
|
393 | + break; |
|
394 | + } |
|
395 | + } else { |
|
396 | + switch (class_basename($model->$key())) { |
|
397 | + /** |
|
398 | + * If the relation is one to one. |
|
399 | + */ |
|
400 | + case 'HasOne': |
|
401 | + /** |
|
402 | + * Save the model. |
|
403 | + */ |
|
404 | + $model->save(); |
|
405 | + $foreignKeyName = $model->$key()->getForeignKeyName(); |
|
406 | + $value->$foreignKeyName = $model->id; |
|
407 | + $value->save(); |
|
408 | + break; |
|
409 | + case 'BelongsTo': |
|
410 | + /** |
|
411 | + * Save the model. |
|
412 | + */ |
|
413 | + $value->save(); |
|
414 | + $model->$key()->associate($value); |
|
415 | + break; |
|
416 | + } |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + /** |
|
421 | + * Save the model. |
|
422 | + */ |
|
423 | + $model->save(); |
|
424 | + }); |
|
425 | 425 | |
426 | - return $model; |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * Delete record from the storage based on the given |
|
431 | - * condition. |
|
432 | - * |
|
433 | - * @param var $value condition value |
|
434 | - * @param string $attribute condition column name |
|
435 | - * @return void |
|
436 | - */ |
|
437 | - public function delete($value, $attribute = 'id') |
|
438 | - { |
|
439 | - if ($attribute == 'id') { |
|
440 | - \DB::transaction(function () use ($value) { |
|
441 | - $model = $this->model->lockForUpdate()->find($value); |
|
442 | - if (! $model) { |
|
443 | - \ErrorHandler::notFound(class_basename($this->model).' with id : '.$value); |
|
444 | - } |
|
426 | + return $model; |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * Delete record from the storage based on the given |
|
431 | + * condition. |
|
432 | + * |
|
433 | + * @param var $value condition value |
|
434 | + * @param string $attribute condition column name |
|
435 | + * @return void |
|
436 | + */ |
|
437 | + public function delete($value, $attribute = 'id') |
|
438 | + { |
|
439 | + if ($attribute == 'id') { |
|
440 | + \DB::transaction(function () use ($value) { |
|
441 | + $model = $this->model->lockForUpdate()->find($value); |
|
442 | + if (! $model) { |
|
443 | + \ErrorHandler::notFound(class_basename($this->model).' with id : '.$value); |
|
444 | + } |
|
445 | 445 | |
446 | - $model->delete(); |
|
447 | - }); |
|
448 | - } else { |
|
449 | - \DB::transaction(function () use ($value, $attribute) { |
|
450 | - $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) { |
|
451 | - $model->delete(); |
|
452 | - }); |
|
453 | - }); |
|
454 | - } |
|
455 | - } |
|
446 | + $model->delete(); |
|
447 | + }); |
|
448 | + } else { |
|
449 | + \DB::transaction(function () use ($value, $attribute) { |
|
450 | + $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) { |
|
451 | + $model->delete(); |
|
452 | + }); |
|
453 | + }); |
|
454 | + } |
|
455 | + } |
|
456 | 456 | |
457 | - /** |
|
458 | - * Fetch records from the storage based on the given |
|
459 | - * id. |
|
460 | - * |
|
461 | - * @param integer $id |
|
462 | - * @param string[] $relations |
|
463 | - * @param array $columns |
|
464 | - * @return object |
|
465 | - */ |
|
466 | - public function find($id, $relations = [], $columns = ['*']) |
|
467 | - { |
|
468 | - return $this->model->with($relations)->find($id, $columns); |
|
469 | - } |
|
457 | + /** |
|
458 | + * Fetch records from the storage based on the given |
|
459 | + * id. |
|
460 | + * |
|
461 | + * @param integer $id |
|
462 | + * @param string[] $relations |
|
463 | + * @param array $columns |
|
464 | + * @return object |
|
465 | + */ |
|
466 | + public function find($id, $relations = [], $columns = ['*']) |
|
467 | + { |
|
468 | + return $this->model->with($relations)->find($id, $columns); |
|
469 | + } |
|
470 | 470 | |
471 | - /** |
|
472 | - * Fetch records from the storage based on the given |
|
473 | - * condition. |
|
474 | - * |
|
475 | - * @param array $conditions array of conditions |
|
476 | - * @param array $relations |
|
477 | - * @param string $sortBy |
|
478 | - * @param boolean $desc |
|
479 | - * @param array $columns |
|
480 | - * @return collection |
|
481 | - */ |
|
482 | - public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
483 | - { |
|
484 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
485 | - $sort = $desc ? 'desc' : 'asc'; |
|
486 | - return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * Fetch the first record from the storage based on the given |
|
491 | - * condition. |
|
492 | - * |
|
493 | - * @param array $conditions array of conditions |
|
494 | - * @param array $relations |
|
495 | - * @param array $columns |
|
496 | - * @return object |
|
497 | - */ |
|
498 | - public function first($conditions, $relations = [], $columns = ['*']) |
|
499 | - { |
|
500 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
501 | - return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
|
502 | - } |
|
503 | - |
|
504 | - /** |
|
505 | - * Return the deleted models in pages based on the given conditions. |
|
506 | - * |
|
507 | - * @param array $conditions array of conditions |
|
508 | - * @param integer $perPage |
|
509 | - * @param string $sortBy |
|
510 | - * @param boolean $desc |
|
511 | - * @param array $columns |
|
512 | - * @return collection |
|
513 | - */ |
|
514 | - public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
515 | - { |
|
516 | - unset($conditions['page']); |
|
517 | - unset($conditions['perPage']); |
|
518 | - unset($conditions['sortBy']); |
|
519 | - unset($conditions['sort']); |
|
520 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
521 | - $sort = $desc ? 'desc' : 'asc'; |
|
522 | - $model = $this->model->onlyTrashed(); |
|
523 | - |
|
524 | - if (count($conditions['conditionValues'])) { |
|
525 | - $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
526 | - } |
|
527 | - |
|
528 | - return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
529 | - } |
|
530 | - |
|
531 | - /** |
|
532 | - * Restore the deleted model. |
|
533 | - * |
|
534 | - * @param integer $id |
|
535 | - * @return void |
|
536 | - */ |
|
537 | - public function restore($id) |
|
538 | - { |
|
539 | - $model = $this->model->onlyTrashed()->find($id); |
|
540 | - |
|
541 | - if (! $model) { |
|
542 | - \ErrorHandler::notFound(class_basename($this->model).' with id : '.$id); |
|
543 | - } |
|
544 | - |
|
545 | - $model->restore(); |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * Build the conditions recursively for the retrieving methods. |
|
550 | - * @param array $conditions |
|
551 | - * @return array |
|
552 | - */ |
|
553 | - protected function constructConditions($conditions, $model) |
|
554 | - { |
|
555 | - $conditionString = ''; |
|
556 | - $conditionValues = []; |
|
557 | - foreach ($conditions as $key => $value) { |
|
558 | - if (Str::contains($key, '->')) { |
|
559 | - $key = $this->wrapJsonSelector($key); |
|
560 | - } |
|
561 | - |
|
562 | - if ($key == 'and') { |
|
563 | - $conditions = $this->constructConditions($value, $model); |
|
564 | - $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} '; |
|
565 | - $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
566 | - } elseif ($key == 'or') { |
|
567 | - $conditions = $this->constructConditions($value, $model); |
|
568 | - $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} '; |
|
569 | - $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
570 | - } else { |
|
571 | - if (is_array($value)) { |
|
572 | - $operator = $value['op']; |
|
573 | - if (strtolower($operator) == 'between') { |
|
574 | - $value1 = $value['val1']; |
|
575 | - $value2 = $value['val2']; |
|
576 | - } else { |
|
577 | - $value = Arr::get($value, 'val', ''); |
|
578 | - } |
|
579 | - } else { |
|
580 | - $operator = '='; |
|
581 | - } |
|
471 | + /** |
|
472 | + * Fetch records from the storage based on the given |
|
473 | + * condition. |
|
474 | + * |
|
475 | + * @param array $conditions array of conditions |
|
476 | + * @param array $relations |
|
477 | + * @param string $sortBy |
|
478 | + * @param boolean $desc |
|
479 | + * @param array $columns |
|
480 | + * @return collection |
|
481 | + */ |
|
482 | + public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
483 | + { |
|
484 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
485 | + $sort = $desc ? 'desc' : 'asc'; |
|
486 | + return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns); |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * Fetch the first record from the storage based on the given |
|
491 | + * condition. |
|
492 | + * |
|
493 | + * @param array $conditions array of conditions |
|
494 | + * @param array $relations |
|
495 | + * @param array $columns |
|
496 | + * @return object |
|
497 | + */ |
|
498 | + public function first($conditions, $relations = [], $columns = ['*']) |
|
499 | + { |
|
500 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
501 | + return $this->model->with($relations)->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * Return the deleted models in pages based on the given conditions. |
|
506 | + * |
|
507 | + * @param array $conditions array of conditions |
|
508 | + * @param integer $perPage |
|
509 | + * @param string $sortBy |
|
510 | + * @param boolean $desc |
|
511 | + * @param array $columns |
|
512 | + * @return collection |
|
513 | + */ |
|
514 | + public function deleted($conditions, $perPage = 15, $sortBy = 'created_at', $desc = 1, $columns = ['*']) |
|
515 | + { |
|
516 | + unset($conditions['page']); |
|
517 | + unset($conditions['perPage']); |
|
518 | + unset($conditions['sortBy']); |
|
519 | + unset($conditions['sort']); |
|
520 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
521 | + $sort = $desc ? 'desc' : 'asc'; |
|
522 | + $model = $this->model->onlyTrashed(); |
|
523 | + |
|
524 | + if (count($conditions['conditionValues'])) { |
|
525 | + $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
526 | + } |
|
527 | + |
|
528 | + return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns); |
|
529 | + } |
|
530 | + |
|
531 | + /** |
|
532 | + * Restore the deleted model. |
|
533 | + * |
|
534 | + * @param integer $id |
|
535 | + * @return void |
|
536 | + */ |
|
537 | + public function restore($id) |
|
538 | + { |
|
539 | + $model = $this->model->onlyTrashed()->find($id); |
|
540 | + |
|
541 | + if (! $model) { |
|
542 | + \ErrorHandler::notFound(class_basename($this->model).' with id : '.$id); |
|
543 | + } |
|
544 | + |
|
545 | + $model->restore(); |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * Build the conditions recursively for the retrieving methods. |
|
550 | + * @param array $conditions |
|
551 | + * @return array |
|
552 | + */ |
|
553 | + protected function constructConditions($conditions, $model) |
|
554 | + { |
|
555 | + $conditionString = ''; |
|
556 | + $conditionValues = []; |
|
557 | + foreach ($conditions as $key => $value) { |
|
558 | + if (Str::contains($key, '->')) { |
|
559 | + $key = $this->wrapJsonSelector($key); |
|
560 | + } |
|
561 | + |
|
562 | + if ($key == 'and') { |
|
563 | + $conditions = $this->constructConditions($value, $model); |
|
564 | + $conditionString .= str_replace('{op}', 'and', $conditions['conditionString']).' {op} '; |
|
565 | + $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
566 | + } elseif ($key == 'or') { |
|
567 | + $conditions = $this->constructConditions($value, $model); |
|
568 | + $conditionString .= str_replace('{op}', 'or', $conditions['conditionString']).' {op} '; |
|
569 | + $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
570 | + } else { |
|
571 | + if (is_array($value)) { |
|
572 | + $operator = $value['op']; |
|
573 | + if (strtolower($operator) == 'between') { |
|
574 | + $value1 = $value['val1']; |
|
575 | + $value2 = $value['val2']; |
|
576 | + } else { |
|
577 | + $value = Arr::get($value, 'val', ''); |
|
578 | + } |
|
579 | + } else { |
|
580 | + $operator = '='; |
|
581 | + } |
|
582 | 582 | |
583 | - if (strtolower($operator) == 'between') { |
|
584 | - $conditionString .= $key.' >= ? and '; |
|
585 | - $conditionValues[] = $value1; |
|
586 | - |
|
587 | - $conditionString .= $key.' <= ? {op} '; |
|
588 | - $conditionValues[] = $value2; |
|
589 | - } elseif (strtolower($operator) == 'in') { |
|
590 | - $conditionValues = array_merge($conditionValues, $value); |
|
591 | - $inBindingsString = rtrim(str_repeat('?,', count($value)), ','); |
|
592 | - $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} '; |
|
593 | - } elseif (strtolower($operator) == 'null') { |
|
594 | - $conditionString .= $key.' is null {op} '; |
|
595 | - } elseif (strtolower($operator) == 'not null') { |
|
596 | - $conditionString .= $key.' is not null {op} '; |
|
597 | - } elseif (strtolower($operator) == 'has') { |
|
598 | - $sql = $model->withTrashed()->has($key)->toSql(); |
|
599 | - $conditions = $this->constructConditions($value, $model->$key()->getRelated()); |
|
600 | - $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} '; |
|
601 | - $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
602 | - } else { |
|
603 | - $conditionString .= $key.' '.$operator.' ? {op} '; |
|
604 | - $conditionValues[] = $value; |
|
605 | - } |
|
606 | - } |
|
607 | - } |
|
608 | - $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
609 | - return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
|
610 | - } |
|
611 | - |
|
612 | - /** |
|
613 | - * Wrap the given JSON selector. |
|
614 | - * |
|
615 | - * @param string $value |
|
616 | - * @return string |
|
617 | - */ |
|
618 | - protected function wrapJsonSelector($value) |
|
619 | - { |
|
620 | - $removeLast = strpos($value, ')'); |
|
621 | - $value = $removeLast === false ? $value : substr($value, 0, $removeLast); |
|
622 | - $path = explode('->', $value); |
|
623 | - $field = array_shift($path); |
|
624 | - $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) { |
|
625 | - return '"'.$part.'"'; |
|
626 | - })->implode('.')); |
|
583 | + if (strtolower($operator) == 'between') { |
|
584 | + $conditionString .= $key.' >= ? and '; |
|
585 | + $conditionValues[] = $value1; |
|
586 | + |
|
587 | + $conditionString .= $key.' <= ? {op} '; |
|
588 | + $conditionValues[] = $value2; |
|
589 | + } elseif (strtolower($operator) == 'in') { |
|
590 | + $conditionValues = array_merge($conditionValues, $value); |
|
591 | + $inBindingsString = rtrim(str_repeat('?,', count($value)), ','); |
|
592 | + $conditionString .= $key.' in ('.rtrim($inBindingsString, ',').') {op} '; |
|
593 | + } elseif (strtolower($operator) == 'null') { |
|
594 | + $conditionString .= $key.' is null {op} '; |
|
595 | + } elseif (strtolower($operator) == 'not null') { |
|
596 | + $conditionString .= $key.' is not null {op} '; |
|
597 | + } elseif (strtolower($operator) == 'has') { |
|
598 | + $sql = $model->withTrashed()->has($key)->toSql(); |
|
599 | + $conditions = $this->constructConditions($value, $model->$key()->getRelated()); |
|
600 | + $conditionString .= rtrim(substr($sql, strpos($sql, 'exists')), ')').' and '.$conditions['conditionString'].') {op} '; |
|
601 | + $conditionValues = array_merge($conditionValues, $conditions['conditionValues']); |
|
602 | + } else { |
|
603 | + $conditionString .= $key.' '.$operator.' ? {op} '; |
|
604 | + $conditionValues[] = $value; |
|
605 | + } |
|
606 | + } |
|
607 | + } |
|
608 | + $conditionString = '('.rtrim($conditionString, '{op} ').')'; |
|
609 | + return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues]; |
|
610 | + } |
|
611 | + |
|
612 | + /** |
|
613 | + * Wrap the given JSON selector. |
|
614 | + * |
|
615 | + * @param string $value |
|
616 | + * @return string |
|
617 | + */ |
|
618 | + protected function wrapJsonSelector($value) |
|
619 | + { |
|
620 | + $removeLast = strpos($value, ')'); |
|
621 | + $value = $removeLast === false ? $value : substr($value, 0, $removeLast); |
|
622 | + $path = explode('->', $value); |
|
623 | + $field = array_shift($path); |
|
624 | + $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) { |
|
625 | + return '"'.$part.'"'; |
|
626 | + })->implode('.')); |
|
627 | 627 | |
628 | - return $removeLast === false ? $result : $result.')'; |
|
629 | - } |
|
628 | + return $removeLast === false ? $result : $result.')'; |
|
629 | + } |
|
630 | 630 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function __construct($model) |
23 | 23 | { |
24 | - $this->model = $model; |
|
24 | + $this->model = $model; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | /** |
86 | 86 | * Construct the select conditions for the model. |
87 | 87 | */ |
88 | - $model->where(function ($q) use ($query, $conditionColumns, $relations) { |
|
88 | + $model->where(function($q) use ($query, $conditionColumns, $relations) { |
|
89 | 89 | |
90 | 90 | if (count($conditionColumns)) { |
91 | 91 | $column = 'LOWER('.array_shift($conditionColumns).')'; |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | /** |
128 | 128 | * Construct the relation condition. |
129 | 129 | */ |
130 | - $q->orWhereHas($relation, function ($subModel) use ($query, $relation) { |
|
130 | + $q->orWhereHas($relation, function($subModel) use ($query, $relation) { |
|
131 | 131 | |
132 | - $subModel->where(function ($q) use ($query, $relation) { |
|
132 | + $subModel->where(function($q) use ($query, $relation) { |
|
133 | 133 | |
134 | 134 | /** |
135 | 135 | * Get columns of the relation. |
@@ -216,14 +216,14 @@ discard block |
||
216 | 216 | $modelClass = $this->model; |
217 | 217 | $relations = []; |
218 | 218 | |
219 | - \DB::transaction(function () use (&$model, &$relations, $data, $modelClass) { |
|
219 | + \DB::transaction(function() use (&$model, &$relations, $data, $modelClass) { |
|
220 | 220 | /** |
221 | 221 | * If the id is present in the data then select the model for updating, |
222 | 222 | * else create new model. |
223 | 223 | * @var array |
224 | 224 | */ |
225 | 225 | $model = Arr::has($data, 'id') ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass; |
226 | - if (! $model) { |
|
226 | + if ( ! $model) { |
|
227 | 227 | \ErrorHandler::notFound(class_basename($modelClass).' with id : '.$data['id']); |
228 | 228 | } |
229 | 229 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * If the relation has no value then marke the relation data |
247 | 247 | * related to the model to be deleted. |
248 | 248 | */ |
249 | - if (! $value || ! count($value)) { |
|
249 | + if ( ! $value || ! count($value)) { |
|
250 | 250 | $relations[$relation] = 'delete'; |
251 | 251 | } |
252 | 252 | } |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | /** |
274 | 274 | * If model doesn't exists. |
275 | 275 | */ |
276 | - if (! $relationModel) { |
|
276 | + if ( ! $relationModel) { |
|
277 | 277 | \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$val['id']); |
278 | 278 | } |
279 | 279 | |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | /** |
305 | 305 | * If model doesn't exists. |
306 | 306 | */ |
307 | - if (! $relationModel) { |
|
307 | + if ( ! $relationModel) { |
|
308 | 308 | \ErrorHandler::notFound(class_basename($relationBaseModel).' with id : '.$value['id']); |
309 | 309 | } |
310 | 310 | |
@@ -437,17 +437,17 @@ discard block |
||
437 | 437 | public function delete($value, $attribute = 'id') |
438 | 438 | { |
439 | 439 | if ($attribute == 'id') { |
440 | - \DB::transaction(function () use ($value) { |
|
440 | + \DB::transaction(function() use ($value) { |
|
441 | 441 | $model = $this->model->lockForUpdate()->find($value); |
442 | - if (! $model) { |
|
442 | + if ( ! $model) { |
|
443 | 443 | \ErrorHandler::notFound(class_basename($this->model).' with id : '.$value); |
444 | 444 | } |
445 | 445 | |
446 | 446 | $model->delete(); |
447 | 447 | }); |
448 | 448 | } else { |
449 | - \DB::transaction(function () use ($value, $attribute) { |
|
450 | - $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function ($model) { |
|
449 | + \DB::transaction(function() use ($value, $attribute) { |
|
450 | + $this->model->where($attribute, '=', $value)->lockForUpdate()->get()->each(function($model) { |
|
451 | 451 | $model->delete(); |
452 | 452 | }); |
453 | 453 | }); |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | { |
539 | 539 | $model = $this->model->onlyTrashed()->find($id); |
540 | 540 | |
541 | - if (! $model) { |
|
541 | + if ( ! $model) { |
|
542 | 542 | \ErrorHandler::notFound(class_basename($this->model).' with id : '.$id); |
543 | 543 | } |
544 | 544 | |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | $value = $removeLast === false ? $value : substr($value, 0, $removeLast); |
622 | 622 | $path = explode('->', $value); |
623 | 623 | $field = array_shift($path); |
624 | - $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function ($part) { |
|
624 | + $result = sprintf('%s->\'$.%s\'', $field, collect($path)->map(function($part) { |
|
625 | 625 | return '"'.$part.'"'; |
626 | 626 | })->implode('.')); |
627 | 627 |
@@ -9,41 +9,41 @@ |
||
9 | 9 | |
10 | 10 | class ConfirmEmail extends Notification implements ShouldQueue |
11 | 11 | { |
12 | - use Queueable; |
|
12 | + use Queueable; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Init new object. |
|
16 | - * |
|
17 | - * @return void |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - // |
|
22 | - } |
|
14 | + /** |
|
15 | + * Init new object. |
|
16 | + * |
|
17 | + * @return void |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + // |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * Get the notification's delivery channels. |
|
26 | - * |
|
27 | - * @param mixed $notifiable |
|
28 | - * @return string[] |
|
29 | - */ |
|
30 | - public function via($notifiable) |
|
31 | - { |
|
32 | - return ['mail']; |
|
33 | - } |
|
24 | + /** |
|
25 | + * Get the notification's delivery channels. |
|
26 | + * |
|
27 | + * @param mixed $notifiable |
|
28 | + * @return string[] |
|
29 | + */ |
|
30 | + public function via($notifiable) |
|
31 | + { |
|
32 | + return ['mail']; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Get the mail representation of the notification. |
|
37 | - * |
|
38 | - * @param mixed $notifiable |
|
39 | - * @return \Illuminate\Notifications\Messages\MailMessage |
|
40 | - */ |
|
41 | - public function toMail($notifiable) |
|
42 | - { |
|
43 | - return (new MailMessage) |
|
44 | - ->subject('Email verification') |
|
45 | - ->line('Email verification') |
|
46 | - ->line('To validate your email click on the button below') |
|
47 | - ->action('Verify your email', config('skeleton.confrim_email_url').'/'.$notifiable->confirmation_code); |
|
48 | - } |
|
35 | + /** |
|
36 | + * Get the mail representation of the notification. |
|
37 | + * |
|
38 | + * @param mixed $notifiable |
|
39 | + * @return \Illuminate\Notifications\Messages\MailMessage |
|
40 | + */ |
|
41 | + public function toMail($notifiable) |
|
42 | + { |
|
43 | + return (new MailMessage) |
|
44 | + ->subject('Email verification') |
|
45 | + ->line('Email verification') |
|
46 | + ->line('To validate your email click on the button below') |
|
47 | + ->action('Verify your email', config('skeleton.confrim_email_url').'/'.$notifiable->confirmation_code); |
|
48 | + } |
|
49 | 49 | } |
@@ -9,43 +9,43 @@ |
||
9 | 9 | |
10 | 10 | class ResetPassword extends Notification implements ShouldQueue |
11 | 11 | { |
12 | - use Queueable; |
|
12 | + use Queueable; |
|
13 | 13 | |
14 | - protected $token; |
|
14 | + protected $token; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Init new object. |
|
18 | - * |
|
19 | - * @return void |
|
20 | - */ |
|
21 | - public function __construct($token) |
|
22 | - { |
|
23 | - $this->token = $token; |
|
24 | - } |
|
16 | + /** |
|
17 | + * Init new object. |
|
18 | + * |
|
19 | + * @return void |
|
20 | + */ |
|
21 | + public function __construct($token) |
|
22 | + { |
|
23 | + $this->token = $token; |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Get the notification's delivery channels. |
|
28 | - * |
|
29 | - * @param mixed $notifiable |
|
30 | - * @return string[] |
|
31 | - */ |
|
32 | - public function via($notifiable) |
|
33 | - { |
|
34 | - return ['mail']; |
|
35 | - } |
|
26 | + /** |
|
27 | + * Get the notification's delivery channels. |
|
28 | + * |
|
29 | + * @param mixed $notifiable |
|
30 | + * @return string[] |
|
31 | + */ |
|
32 | + public function via($notifiable) |
|
33 | + { |
|
34 | + return ['mail']; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Get the mail representation of the notification. |
|
39 | - * |
|
40 | - * @param mixed $notifiable |
|
41 | - * @return \Illuminate\Notifications\Messages\MailMessage |
|
42 | - */ |
|
43 | - public function toMail($notifiable) |
|
44 | - { |
|
45 | - return (new MailMessage) |
|
46 | - ->subject('Reset passowrd') |
|
47 | - ->line('Reset passowrd') |
|
48 | - ->line('To reset your password click on the button below') |
|
49 | - ->action('Reset password', config('skeleton.reset_password_url').'/'.$this->token); |
|
50 | - } |
|
37 | + /** |
|
38 | + * Get the mail representation of the notification. |
|
39 | + * |
|
40 | + * @param mixed $notifiable |
|
41 | + * @return \Illuminate\Notifications\Messages\MailMessage |
|
42 | + */ |
|
43 | + public function toMail($notifiable) |
|
44 | + { |
|
45 | + return (new MailMessage) |
|
46 | + ->subject('Reset passowrd') |
|
47 | + ->line('Reset passowrd') |
|
48 | + ->line('To reset your password click on the button below') |
|
49 | + ->action('Reset password', config('skeleton.reset_password_url').'/'.$this->token); |
|
50 | + } |
|
51 | 51 | } |
@@ -2,15 +2,15 @@ |
||
2 | 2 | |
3 | 3 | interface BaseFactoryInterface |
4 | 4 | { |
5 | - /** |
|
6 | - * Construct the repository class name based on |
|
7 | - * the method name called, search in the |
|
8 | - * given namespaces for the class and |
|
9 | - * return an instance. |
|
10 | - * |
|
11 | - * @param string $name the called method name |
|
12 | - * @param array $arguments the method arguments |
|
13 | - * @return object |
|
14 | - */ |
|
15 | - public function __call($name, $arguments); |
|
5 | + /** |
|
6 | + * Construct the repository class name based on |
|
7 | + * the method name called, search in the |
|
8 | + * given namespaces for the class and |
|
9 | + * return an instance. |
|
10 | + * |
|
11 | + * @param string $name the called method name |
|
12 | + * @param array $arguments the method arguments |
|
13 | + * @return object |
|
14 | + */ |
|
15 | + public function __call($name, $arguments); |
|
16 | 16 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | * Init new object. |
35 | 35 | * |
36 | 36 | * @param mixed $repo |
37 | - * @param CoreConfig $config |
|
37 | + * @param \App\Modules\Core\Utl\CoreConfig $config |
|
38 | 38 | * @param string $modelResource |
39 | 39 | * @return void |
40 | 40 | */ |
@@ -10,204 +10,204 @@ |
||
10 | 10 | |
11 | 11 | class BaseApiController extends Controller |
12 | 12 | { |
13 | - /** |
|
14 | - * The config implementation. |
|
15 | - * |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $config; |
|
19 | - |
|
20 | - /** |
|
21 | - * The relations implementation. |
|
22 | - * |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $relations; |
|
26 | - |
|
27 | - /** |
|
28 | - * The repo implementation. |
|
29 | - * |
|
30 | - * @var object |
|
31 | - */ |
|
32 | - protected $repo; |
|
33 | - |
|
34 | - /** |
|
35 | - * Init new object. |
|
36 | - * |
|
37 | - * @param mixed $repo |
|
38 | - * @param CoreConfig $config |
|
39 | - * @param string $modelResource |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - public function __construct($repo, $config, $modelResource) |
|
43 | - { |
|
44 | - $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
45 | - $this->modelResource = $modelResource; |
|
46 | - $this->config = $config->getConfig(); |
|
47 | - $this->modelName = explode('\\', get_called_class()); |
|
48 | - $this->modelName = lcfirst(str_replace('Controller', '', end($this->modelName))); |
|
49 | - $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
50 | - $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
51 | - $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
52 | - $route = explode('@', \Route::currentRouteAction())[1]; |
|
53 | - |
|
54 | - $this->setSessions(); |
|
55 | - $this->checkPermission($route); |
|
56 | - $this->setRelations($route); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Fetch all records with relations from storage. |
|
61 | - * |
|
62 | - * @param Request $request |
|
63 | - * @return \Illuminate\Http\Response |
|
64 | - */ |
|
65 | - public function index(Request $request) |
|
66 | - { |
|
67 | - return $this->modelResource::collection($this->repo->list($this->relations, $request->query(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Fetch the single object with relations from storage. |
|
72 | - * |
|
73 | - * @param integer $id Id of the requested model. |
|
74 | - * @return \Illuminate\Http\Response |
|
75 | - */ |
|
76 | - public function find($id) |
|
77 | - { |
|
78 | - return new $this->modelResource($this->repo->find($id, $this->relations)); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Delete by the given id from storage. |
|
83 | - * |
|
84 | - * @param integer $id Id of the deleted model. |
|
85 | - * @return \Illuminate\Http\Response |
|
86 | - */ |
|
87 | - public function delete($id) |
|
88 | - { |
|
89 | - return new GeneralResource($this->repo->delete($id)); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Return the deleted models in pages based on the given conditions. |
|
94 | - * |
|
95 | - * @param Request $request |
|
96 | - * @return \Illuminate\Http\Response |
|
97 | - */ |
|
98 | - public function deleted(Request $request) |
|
99 | - { |
|
100 | - return $this->modelResource::collection($this->repo->deleted($request->all(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Restore the deleted model. |
|
105 | - * |
|
106 | - * @param integer $id Id of the restored model. |
|
107 | - * @return \Illuminate\Http\Response |
|
108 | - */ |
|
109 | - public function restore($id) |
|
110 | - { |
|
111 | - return new GeneralResource($this->repo->restore($id)); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Check if the logged in user can do the given permission. |
|
116 | - * |
|
117 | - * @param string $permission |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - private function checkPermission($permission) |
|
121 | - { |
|
122 | - \Auth::shouldUse('api'); |
|
123 | - $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
13 | + /** |
|
14 | + * The config implementation. |
|
15 | + * |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $config; |
|
19 | + |
|
20 | + /** |
|
21 | + * The relations implementation. |
|
22 | + * |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $relations; |
|
26 | + |
|
27 | + /** |
|
28 | + * The repo implementation. |
|
29 | + * |
|
30 | + * @var object |
|
31 | + */ |
|
32 | + protected $repo; |
|
33 | + |
|
34 | + /** |
|
35 | + * Init new object. |
|
36 | + * |
|
37 | + * @param mixed $repo |
|
38 | + * @param CoreConfig $config |
|
39 | + * @param string $modelResource |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + public function __construct($repo, $config, $modelResource) |
|
43 | + { |
|
44 | + $this->repo = new CachingDecorator($repo, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
45 | + $this->modelResource = $modelResource; |
|
46 | + $this->config = $config->getConfig(); |
|
47 | + $this->modelName = explode('\\', get_called_class()); |
|
48 | + $this->modelName = lcfirst(str_replace('Controller', '', end($this->modelName))); |
|
49 | + $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
50 | + $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
51 | + $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
52 | + $route = explode('@', \Route::currentRouteAction())[1]; |
|
53 | + |
|
54 | + $this->setSessions(); |
|
55 | + $this->checkPermission($route); |
|
56 | + $this->setRelations($route); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Fetch all records with relations from storage. |
|
61 | + * |
|
62 | + * @param Request $request |
|
63 | + * @return \Illuminate\Http\Response |
|
64 | + */ |
|
65 | + public function index(Request $request) |
|
66 | + { |
|
67 | + return $this->modelResource::collection($this->repo->list($this->relations, $request->query(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Fetch the single object with relations from storage. |
|
72 | + * |
|
73 | + * @param integer $id Id of the requested model. |
|
74 | + * @return \Illuminate\Http\Response |
|
75 | + */ |
|
76 | + public function find($id) |
|
77 | + { |
|
78 | + return new $this->modelResource($this->repo->find($id, $this->relations)); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Delete by the given id from storage. |
|
83 | + * |
|
84 | + * @param integer $id Id of the deleted model. |
|
85 | + * @return \Illuminate\Http\Response |
|
86 | + */ |
|
87 | + public function delete($id) |
|
88 | + { |
|
89 | + return new GeneralResource($this->repo->delete($id)); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Return the deleted models in pages based on the given conditions. |
|
94 | + * |
|
95 | + * @param Request $request |
|
96 | + * @return \Illuminate\Http\Response |
|
97 | + */ |
|
98 | + public function deleted(Request $request) |
|
99 | + { |
|
100 | + return $this->modelResource::collection($this->repo->deleted($request->all(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'))); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Restore the deleted model. |
|
105 | + * |
|
106 | + * @param integer $id Id of the restored model. |
|
107 | + * @return \Illuminate\Http\Response |
|
108 | + */ |
|
109 | + public function restore($id) |
|
110 | + { |
|
111 | + return new GeneralResource($this->repo->restore($id)); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Check if the logged in user can do the given permission. |
|
116 | + * |
|
117 | + * @param string $permission |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + private function checkPermission($permission) |
|
121 | + { |
|
122 | + \Auth::shouldUse('api'); |
|
123 | + $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
124 | 124 | |
125 | - if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
126 | - $user = \Auth::user(); |
|
127 | - $isPasswordClient = $user->token()->client->password_client; |
|
128 | - $this->updateLocaleAndTimezone($user); |
|
129 | - |
|
130 | - if ($user->blocked) { |
|
131 | - \ErrorHandler::userIsBlocked(); |
|
132 | - } |
|
133 | - |
|
134 | - if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
|
135 | - } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
136 | - } else { |
|
137 | - \ErrorHandler::noPermissions(); |
|
138 | - } |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Set sessions based on the given headers in the request. |
|
144 | - * |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - private function setSessions() |
|
148 | - { |
|
149 | - \Session::put('time-zone', \Request::header('time-zone') ?: 0); |
|
150 | - |
|
151 | - $locale = \Request::header('locale'); |
|
152 | - switch ($locale) { |
|
153 | - case 'en': |
|
154 | - \App::setLocale('en'); |
|
155 | - \Session::put('locale', 'en'); |
|
156 | - break; |
|
157 | - |
|
158 | - case 'ar': |
|
159 | - \App::setLocale('ar'); |
|
160 | - \Session::put('locale', 'ar'); |
|
161 | - break; |
|
162 | - |
|
163 | - case 'all': |
|
164 | - \App::setLocale('en'); |
|
165 | - \Session::put('locale', 'all'); |
|
166 | - break; |
|
167 | - |
|
168 | - default: |
|
169 | - \App::setLocale('en'); |
|
170 | - \Session::put('locale', 'en'); |
|
171 | - break; |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Set relation based on the called api. |
|
177 | - * |
|
178 | - * @param string $route |
|
179 | - * @return void |
|
180 | - */ |
|
181 | - private function setRelations($route) |
|
182 | - { |
|
183 | - $route = $route !== 'index' ? $route : 'list'; |
|
184 | - $relations = Arr::get($this->config['relations'], $this->modelName, false); |
|
185 | - $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Update the logged in user locale and time zone. |
|
190 | - * |
|
191 | - * @param object $user |
|
192 | - * @return void |
|
193 | - */ |
|
194 | - private function updateLocaleAndTimezone($user) |
|
195 | - { |
|
196 | - $update = false; |
|
197 | - $locale = \Session::get('locale'); |
|
198 | - $timezone = \Session::get('time-zone'); |
|
199 | - if ($locale && $locale !== 'all' && $locale !== $user->locale) { |
|
200 | - $user->locale = $locale; |
|
201 | - $update = true; |
|
202 | - } |
|
203 | - |
|
204 | - if ($timezone && $timezone !== $user->timezone) { |
|
205 | - $user->timezone = $timezone; |
|
206 | - $update = true; |
|
207 | - } |
|
208 | - |
|
209 | - if ($update) { |
|
210 | - $user->save(); |
|
211 | - } |
|
212 | - } |
|
125 | + if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
126 | + $user = \Auth::user(); |
|
127 | + $isPasswordClient = $user->token()->client->password_client; |
|
128 | + $this->updateLocaleAndTimezone($user); |
|
129 | + |
|
130 | + if ($user->blocked) { |
|
131 | + \ErrorHandler::userIsBlocked(); |
|
132 | + } |
|
133 | + |
|
134 | + if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
|
135 | + } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
136 | + } else { |
|
137 | + \ErrorHandler::noPermissions(); |
|
138 | + } |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Set sessions based on the given headers in the request. |
|
144 | + * |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + private function setSessions() |
|
148 | + { |
|
149 | + \Session::put('time-zone', \Request::header('time-zone') ?: 0); |
|
150 | + |
|
151 | + $locale = \Request::header('locale'); |
|
152 | + switch ($locale) { |
|
153 | + case 'en': |
|
154 | + \App::setLocale('en'); |
|
155 | + \Session::put('locale', 'en'); |
|
156 | + break; |
|
157 | + |
|
158 | + case 'ar': |
|
159 | + \App::setLocale('ar'); |
|
160 | + \Session::put('locale', 'ar'); |
|
161 | + break; |
|
162 | + |
|
163 | + case 'all': |
|
164 | + \App::setLocale('en'); |
|
165 | + \Session::put('locale', 'all'); |
|
166 | + break; |
|
167 | + |
|
168 | + default: |
|
169 | + \App::setLocale('en'); |
|
170 | + \Session::put('locale', 'en'); |
|
171 | + break; |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Set relation based on the called api. |
|
177 | + * |
|
178 | + * @param string $route |
|
179 | + * @return void |
|
180 | + */ |
|
181 | + private function setRelations($route) |
|
182 | + { |
|
183 | + $route = $route !== 'index' ? $route : 'list'; |
|
184 | + $relations = Arr::get($this->config['relations'], $this->modelName, false); |
|
185 | + $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Update the logged in user locale and time zone. |
|
190 | + * |
|
191 | + * @param object $user |
|
192 | + * @return void |
|
193 | + */ |
|
194 | + private function updateLocaleAndTimezone($user) |
|
195 | + { |
|
196 | + $update = false; |
|
197 | + $locale = \Session::get('locale'); |
|
198 | + $timezone = \Session::get('time-zone'); |
|
199 | + if ($locale && $locale !== 'all' && $locale !== $user->locale) { |
|
200 | + $user->locale = $locale; |
|
201 | + $update = true; |
|
202 | + } |
|
203 | + |
|
204 | + if ($timezone && $timezone !== $user->timezone) { |
|
205 | + $user->timezone = $timezone; |
|
206 | + $update = true; |
|
207 | + } |
|
208 | + |
|
209 | + if ($update) { |
|
210 | + $user->save(); |
|
211 | + } |
|
212 | + } |
|
213 | 213 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | \Auth::shouldUse('api'); |
123 | 123 | $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
124 | 124 | |
125 | - if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
125 | + if ( ! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
126 | 126 | $user = \Auth::user(); |
127 | 127 | $isPasswordClient = $user->token()->client->password_client; |
128 | 128 | $this->updateLocaleAndTimezone($user); |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | } |
133 | 133 | |
134 | 134 | if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
135 | - } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
135 | + } elseif ( ! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
136 | 136 | } else { |
137 | 137 | \ErrorHandler::noPermissions(); |
138 | 138 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | |
204 | 204 | if ($timezone && $timezone !== $user->timezone) { |
205 | 205 | $user->timezone = $timezone; |
206 | - $update = true; |
|
206 | + $update = true; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | if ($update) { |
@@ -33,7 +33,7 @@ |
||
33 | 33 | * |
34 | 34 | * @param Request $request |
35 | 35 | * @param string $reportName Name of the requested report |
36 | - * @return \Illuminate\Http\Response |
|
36 | + * @return \Illuminate\Http\JsonResponse |
|
37 | 37 | */ |
38 | 38 | public function getReport(Request $request, $reportName) |
39 | 39 | { |
@@ -9,34 +9,34 @@ |
||
9 | 9 | |
10 | 10 | class ReportController extends BaseApiController |
11 | 11 | { |
12 | - /** |
|
13 | - * List of all route actions that the base api controller |
|
14 | - * will skip permissions check for them. |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - protected $skipPermissionCheck = ['getReport']; |
|
12 | + /** |
|
13 | + * List of all route actions that the base api controller |
|
14 | + * will skip permissions check for them. |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + protected $skipPermissionCheck = ['getReport']; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Init new object. |
|
21 | - * |
|
22 | - * @param ReportRepository $repo |
|
23 | - * @param CoreConfig $config |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function __construct(ReportRepository $repo, CoreConfig $config) |
|
27 | - { |
|
28 | - parent::__construct($repo, $config, 'App\Modules\Reporting\Http\Resources\Report'); |
|
29 | - } |
|
19 | + /** |
|
20 | + * Init new object. |
|
21 | + * |
|
22 | + * @param ReportRepository $repo |
|
23 | + * @param CoreConfig $config |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function __construct(ReportRepository $repo, CoreConfig $config) |
|
27 | + { |
|
28 | + parent::__construct($repo, $config, 'App\Modules\Reporting\Http\Resources\Report'); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Render the given report name with the given conditions. |
|
33 | - * |
|
34 | - * @param Request $request |
|
35 | - * @param string $reportName Name of the requested report |
|
36 | - * @return \Illuminate\Http\Response |
|
37 | - */ |
|
38 | - public function getReport(Request $request, $reportName) |
|
39 | - { |
|
40 | - return \Response::json($this->repo->getReport($reportName, $request->all(), $request->query('perPage')), 200); |
|
41 | - } |
|
31 | + /** |
|
32 | + * Render the given report name with the given conditions. |
|
33 | + * |
|
34 | + * @param Request $request |
|
35 | + * @param string $reportName Name of the requested report |
|
36 | + * @return \Illuminate\Http\Response |
|
37 | + */ |
|
38 | + public function getReport(Request $request, $reportName) |
|
39 | + { |
|
40 | + return \Response::json($this->repo->getReport($reportName, $request->all(), $request->query('perPage')), 200); |
|
41 | + } |
|
42 | 42 | } |
@@ -6,46 +6,46 @@ |
||
6 | 6 | |
7 | 7 | class NotificationsTableSeeder extends Seeder |
8 | 8 | { |
9 | - /** |
|
10 | - * Run the database seeds. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function run() |
|
15 | - { |
|
16 | - /** |
|
17 | - * Insert the permissions related to settings table. |
|
18 | - */ |
|
19 | - \DB::table('permissions')->insert( |
|
20 | - [ |
|
21 | - /** |
|
22 | - * notifications model permissions. |
|
23 | - */ |
|
24 | - [ |
|
25 | - 'name' => 'all', |
|
26 | - 'model' => 'notification', |
|
27 | - 'created_at' => \DB::raw('NOW()'), |
|
28 | - 'updated_at' => \DB::raw('NOW()') |
|
29 | - ], |
|
30 | - [ |
|
31 | - 'name' => 'unread', |
|
32 | - 'model' => 'notification', |
|
33 | - 'created_at' => \DB::raw('NOW()'), |
|
34 | - 'updated_at' => \DB::raw('NOW()') |
|
35 | - ], |
|
36 | - [ |
|
37 | - 'name' => 'markAsRead', |
|
38 | - 'model' => 'notification', |
|
39 | - 'created_at' => \DB::raw('NOW()'), |
|
40 | - 'updated_at' => \DB::raw('NOW()') |
|
41 | - ], |
|
42 | - [ |
|
43 | - 'name' => 'markAllAsRead', |
|
44 | - 'model' => 'notification', |
|
45 | - 'created_at' => \DB::raw('NOW()'), |
|
46 | - 'updated_at' => \DB::raw('NOW()') |
|
47 | - ] |
|
48 | - ] |
|
49 | - ); |
|
50 | - } |
|
9 | + /** |
|
10 | + * Run the database seeds. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function run() |
|
15 | + { |
|
16 | + /** |
|
17 | + * Insert the permissions related to settings table. |
|
18 | + */ |
|
19 | + \DB::table('permissions')->insert( |
|
20 | + [ |
|
21 | + /** |
|
22 | + * notifications model permissions. |
|
23 | + */ |
|
24 | + [ |
|
25 | + 'name' => 'all', |
|
26 | + 'model' => 'notification', |
|
27 | + 'created_at' => \DB::raw('NOW()'), |
|
28 | + 'updated_at' => \DB::raw('NOW()') |
|
29 | + ], |
|
30 | + [ |
|
31 | + 'name' => 'unread', |
|
32 | + 'model' => 'notification', |
|
33 | + 'created_at' => \DB::raw('NOW()'), |
|
34 | + 'updated_at' => \DB::raw('NOW()') |
|
35 | + ], |
|
36 | + [ |
|
37 | + 'name' => 'markAsRead', |
|
38 | + 'model' => 'notification', |
|
39 | + 'created_at' => \DB::raw('NOW()'), |
|
40 | + 'updated_at' => \DB::raw('NOW()') |
|
41 | + ], |
|
42 | + [ |
|
43 | + 'name' => 'markAllAsRead', |
|
44 | + 'model' => 'notification', |
|
45 | + 'created_at' => \DB::raw('NOW()'), |
|
46 | + 'updated_at' => \DB::raw('NOW()') |
|
47 | + ] |
|
48 | + ] |
|
49 | + ); |
|
50 | + } |
|
51 | 51 | } |