@@ -25,7 +25,7 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | public static function bootBakeryTransactionalAware() |
| 27 | 27 | { |
| 28 | - Event::listen('eloquent.booted: '.static::class, function (Model $model) { |
|
| 28 | + Event::listen('eloquent.booted: '.static::class, function(Model $model) { |
|
| 29 | 29 | $model->addObservableEvents(['persisting', 'persisted']); |
| 30 | 30 | }); |
| 31 | 31 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public function create(array $input = []): Model |
| 62 | 62 | { |
| 63 | - return $this->transaction(function () use ($input) { |
|
| 63 | + return $this->transaction(function() use ($input) { |
|
| 64 | 64 | $this->make($input); |
| 65 | 65 | $this->save(); |
| 66 | 66 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function createIfAuthorized(array $input = []): Model |
| 78 | 78 | { |
| 79 | - return $this->transaction(function () use ($input) { |
|
| 79 | + return $this->transaction(function() use ($input) { |
|
| 80 | 80 | $this->create($input); |
| 81 | 81 | $this->authorizeToCreate(); |
| 82 | 82 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | public function update(array $input = []): Model |
| 107 | 107 | { |
| 108 | - return $this->transaction(function () use ($input) { |
|
| 108 | + return $this->transaction(function() use ($input) { |
|
| 109 | 109 | $this->fill($input); |
| 110 | 110 | $this->save(); |
| 111 | 111 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | public function authorizeToCreate(): void |
| 19 | 19 | { |
| 20 | - if (! static::authorizedToCreate()) { |
|
| 20 | + if (!static::authorizedToCreate()) { |
|
| 21 | 21 | throw new AuthorizationException("Not allowed to perform create on {$this->getModelClass()}"); |
| 22 | 22 | } |
| 23 | 23 | } |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | public function authorize(string $ability, $arguments = []): void |
| 167 | 167 | { |
| 168 | - if (! $this->authorized($ability, $arguments)) { |
|
| 168 | + if (!$this->authorized($ability, $arguments)) { |
|
| 169 | 169 | throw new AuthorizationException("Not allowed to perform {$ability} on {$this->getModelClass()}"); |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | $relationType = $this->getRelationTypeName($relation); |
| 62 | 62 | $method = "fill{$relationType}Relation"; |
| 63 | 63 | |
| 64 | - if (! method_exists($this, $method)) { |
|
| 64 | + if (!method_exists($this, $method)) { |
|
| 65 | 65 | throw new RuntimeException("Unknown or unfillable relation type: {$key} of type ${relationType}"); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $relationType = $this->getRelationTypeName($relation); |
| 83 | 83 | $method = "connect{$relationType}Relation"; |
| 84 | 84 | |
| 85 | - if (! method_exists($this, $method)) { |
|
| 85 | + if (!method_exists($this, $method)) { |
|
| 86 | 86 | throw new RuntimeException("Unknown or unfillable connection type: {$key} of type ${relationType}"); |
| 87 | 87 | } |
| 88 | 88 | |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | protected function connectBelongsToRelation(Relations\BelongsTo $relation, $id) |
| 101 | 101 | { |
| 102 | - if (! $id) { |
|
| 102 | + if (!$id) { |
|
| 103 | 103 | $relation->dissociate(); |
| 104 | 104 | |
| 105 | 105 | return; |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | $relation->associate($model); |
| 112 | 112 | |
| 113 | - $this->queue(function () use ($schema) { |
|
| 113 | + $this->queue(function() use ($schema) { |
|
| 114 | 114 | $schema->authorizeToAdd($this->getModel()); |
| 115 | 115 | }); |
| 116 | 116 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | protected function fillBelongsToRelation(Relations\BelongsTo $relation, $attributes = []) |
| 126 | 126 | { |
| 127 | - if (! $attributes) { |
|
| 127 | + if (!$attributes) { |
|
| 128 | 128 | $relation->dissociate(); |
| 129 | 129 | |
| 130 | 130 | return; |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | |
| 137 | 137 | $relation->associate($model); |
| 138 | 138 | |
| 139 | - $this->queue(function () use ($schema) { |
|
| 139 | + $this->queue(function() use ($schema) { |
|
| 140 | 140 | $schema->authorizeToAdd($this->getModel()); |
| 141 | 141 | }); |
| 142 | 142 | } |
@@ -150,13 +150,13 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | protected function connectHasOneRelation(Relations\HasOne $relation, $id) |
| 152 | 152 | { |
| 153 | - if (! $id) { |
|
| 153 | + if (!$id) { |
|
| 154 | 154 | $relation->delete(); |
| 155 | 155 | |
| 156 | 156 | return; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - $this->queue(function () use ($id, $relation) { |
|
| 159 | + $this->queue(function() use ($id, $relation) { |
|
| 160 | 160 | $model = $relation->getRelated()->findOrFail($id); |
| 161 | 161 | $this->authorizeToAdd($model); |
| 162 | 162 | $relation->save($model); |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | protected function fillHasOneRelation(Relations\HasOne $relation, $attributes) |
| 175 | 175 | { |
| 176 | - if (! $attributes) { |
|
| 176 | + if (!$attributes) { |
|
| 177 | 177 | $relation->delete(); |
| 178 | 178 | |
| 179 | 179 | return; |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | $modelSchema->authorizeToCreate(); |
| 185 | 185 | $modelSchema->fill($attributes); |
| 186 | 186 | |
| 187 | - $this->queue(function () use ($modelSchema, $relation) { |
|
| 187 | + $this->queue(function() use ($modelSchema, $relation) { |
|
| 188 | 188 | $this->authorizeToAdd($modelSchema->getModel()); |
| 189 | 189 | $relation->save($modelSchema->getInstance()); |
| 190 | 190 | $modelSchema->save(); |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | protected function connectHasManyRelation(Relations\HasMany $relation, array $ids) |
| 202 | 202 | { |
| 203 | - $this->queue(function () use ($relation, $ids) { |
|
| 203 | + $this->queue(function() use ($relation, $ids) { |
|
| 204 | 204 | $models = $relation->getModel()->findMany($ids); |
| 205 | 205 | |
| 206 | 206 | foreach ($models as $model) { |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | protected function fillHasManyRelation(Relations\HasMany $relation, array $values) |
| 222 | 222 | { |
| 223 | - $this->queue(function () use ($relation, $values) { |
|
| 223 | + $this->queue(function() use ($relation, $values) { |
|
| 224 | 224 | $related = $relation->getRelated(); |
| 225 | 225 | $relation->delete(); |
| 226 | 226 | |
@@ -269,20 +269,20 @@ discard block |
||
| 269 | 269 | ) { |
| 270 | 270 | $values = collect($values); |
| 271 | 271 | |
| 272 | - $this->queue(function () use ($detaching, $relation, $values) { |
|
| 272 | + $this->queue(function() use ($detaching, $relation, $values) { |
|
| 273 | 273 | $current = $relation->newQuery()->pluck($relation->getRelatedPivotKeyName()); |
| 274 | 274 | |
| 275 | 275 | if ($detaching) { |
| 276 | 276 | $detach = $current->diff($values); |
| 277 | 277 | |
| 278 | - $relation->getRelated()->newQuery()->findMany($detach)->each(function (Model $model) { |
|
| 278 | + $relation->getRelated()->newQuery()->findMany($detach)->each(function(Model $model) { |
|
| 279 | 279 | $this->authorizeToDetach($model); |
| 280 | 280 | }); |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | $attach = $values->diff($current); |
| 284 | 284 | |
| 285 | - $relation->getRelated()->newQuery()->findMany($attach)->each(function (Model $model) { |
|
| 285 | + $relation->getRelated()->newQuery()->findMany($attach)->each(function(Model $model) { |
|
| 286 | 286 | $this->authorizeToAttach($model); |
| 287 | 287 | }); |
| 288 | 288 | |
@@ -309,9 +309,9 @@ discard block |
||
| 309 | 309 | $pivotClass = $relation->getPivotClass(); |
| 310 | 310 | |
| 311 | 311 | // Returns an associative array of [ id => pivot ] |
| 312 | - $values = collect($values)->mapWithKeys(function ($data) use ($accessor, $relatedKey) { |
|
| 312 | + $values = collect($values)->mapWithKeys(function($data) use ($accessor, $relatedKey) { |
|
| 313 | 313 | return [$data[$relatedKey] => $data[$accessor] ?? []]; |
| 314 | - })->map(function ($attributes) use ($pivotClass) { |
|
| 314 | + })->map(function($attributes) use ($pivotClass) { |
|
| 315 | 315 | $instance = new $pivotClass; |
| 316 | 316 | $pivotSchema = $this->registry->getSchemaForModel($instance); |
| 317 | 317 | $pivotSchema->fill($attributes); |
@@ -319,20 +319,20 @@ discard block |
||
| 319 | 319 | return $pivotSchema->getInstance()->getAttributes(); |
| 320 | 320 | }); |
| 321 | 321 | |
| 322 | - $this->queue(function () use ($values, $detaching, $relation) { |
|
| 322 | + $this->queue(function() use ($values, $detaching, $relation) { |
|
| 323 | 323 | $current = $relation->newQuery()->pluck($relation->getRelatedPivotKeyName()); |
| 324 | 324 | |
| 325 | 325 | if ($detaching) { |
| 326 | 326 | $detach = $current->diff($values->keys()); |
| 327 | 327 | |
| 328 | - $relation->getRelated()->newQuery()->findMany($detach)->each(function (Model $model) { |
|
| 328 | + $relation->getRelated()->newQuery()->findMany($detach)->each(function(Model $model) { |
|
| 329 | 329 | $this->authorizeToDetach($model); |
| 330 | 330 | }); |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | $attach = $values->keys()->diff($current); |
| 334 | 334 | |
| 335 | - $relation->getRelated()->newQuery()->findMany($attach)->each(function (Model $model) use ($values) { |
|
| 335 | + $relation->getRelated()->newQuery()->findMany($attach)->each(function(Model $model) use ($values) { |
|
| 336 | 336 | $this->authorizeToAttach($model, $values->get($model->getKey())); |
| 337 | 337 | }); |
| 338 | 338 | |
@@ -361,8 +361,8 @@ discard block |
||
| 361 | 361 | $pivots[] = $attributes[$accessor] ?? null; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - $this->queue(function () use ($detaching, $relation, $instances, $pivots) { |
|
| 365 | - $data = $instances->pluck('id')->mapWithKeys(function ($id, $key) use ($pivots) { |
|
| 364 | + $this->queue(function() use ($detaching, $relation, $instances, $pivots) { |
|
| 365 | + $data = $instances->pluck('id')->mapWithKeys(function($id, $key) use ($pivots) { |
|
| 366 | 366 | $pivot = $pivots[$key] ?? null; |
| 367 | 367 | |
| 368 | 368 | return $pivot ? [$id => $pivot] : [$key => $id]; |
@@ -370,11 +370,11 @@ discard block |
||
| 370 | 370 | |
| 371 | 371 | $results = $relation->sync($data, $detaching); |
| 372 | 372 | |
| 373 | - $relation->getRelated()->newQuery()->findMany($results['detached'])->each(function (Model $model) { |
|
| 373 | + $relation->getRelated()->newQuery()->findMany($results['detached'])->each(function(Model $model) { |
|
| 374 | 374 | $this->authorizeToDetach($model); |
| 375 | 375 | }); |
| 376 | 376 | |
| 377 | - $relation->getRelated()->newQuery()->findMany($results['attached'])->each(function (Model $model) { |
|
| 377 | + $relation->getRelated()->newQuery()->findMany($results['attached'])->each(function(Model $model) { |
|
| 378 | 378 | $this->authorizeToAttach($model); |
| 379 | 379 | }); |
| 380 | 380 | }); |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | */ |
| 390 | 390 | protected function connectMorphToRelation(Relations\MorphTo $relation, $data) |
| 391 | 391 | { |
| 392 | - if (! $data) { |
|
| 392 | + if (!$data) { |
|
| 393 | 393 | $relation->dissociate(); |
| 394 | 394 | |
| 395 | 395 | return; |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | |
| 403 | 403 | $data = collect($data); |
| 404 | 404 | |
| 405 | - [$key, $id] = $data->mapWithKeys(function ($item, $key) { |
|
| 405 | + [$key, $id] = $data->mapWithKeys(function($item, $key) { |
|
| 406 | 406 | return [$key, $item]; |
| 407 | 407 | }); |
| 408 | 408 | |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | */ |
| 425 | 425 | protected function fillMorphToRelation(Relations\MorphTo $relation, $data) |
| 426 | 426 | { |
| 427 | - if (! $data) { |
|
| 427 | + if (!$data) { |
|
| 428 | 428 | $relation->dissociate(); |
| 429 | 429 | |
| 430 | 430 | return; |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | |
| 438 | 438 | $data = collect($data); |
| 439 | 439 | |
| 440 | - [$key, $attributes] = $data->mapWithKeys(function ($item, $key) { |
|
| 440 | + [$key, $attributes] = $data->mapWithKeys(function($item, $key) { |
|
| 441 | 441 | return [$key, $item]; |
| 442 | 442 | }); |
| 443 | 443 | |
@@ -473,8 +473,8 @@ discard block |
||
| 473 | 473 | */ |
| 474 | 474 | protected function connectMorphManyRelation(Relations\MorphMany $relation, array $ids) |
| 475 | 475 | { |
| 476 | - $this->queue(function () use ($relation, $ids) { |
|
| 477 | - $relation->each(function (Model $model) use ($relation) { |
|
| 476 | + $this->queue(function() use ($relation, $ids) { |
|
| 477 | + $relation->each(function(Model $model) use ($relation) { |
|
| 478 | 478 | $model->setAttribute($relation->getMorphType(), null); |
| 479 | 479 | $model->setAttribute($relation->getForeignKeyName(), null); |
| 480 | 480 | $model->save(); |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | */ |
| 496 | 496 | protected function fillMorphManyRelation(Relations\MorphMany $relation, array $values) |
| 497 | 497 | { |
| 498 | - $this->queue(function () use ($relation, $values) { |
|
| 498 | + $this->queue(function() use ($relation, $values) { |
|
| 499 | 499 | $relation->delete(); |
| 500 | 500 | $related = $relation->getRelated(); |
| 501 | 501 | $relatedSchema = $this->registry->getSchemaForModel($related); |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | * |
| 15 | 15 | * @throws \InvalidArgumentException |
| 16 | 16 | */ |
| 17 | -Builder::macro('bakeryPaginate', function ($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) { |
|
| 17 | +Builder::macro('bakeryPaginate', function($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) { |
|
| 18 | 18 | $page = $page ?: Paginator::resolveCurrentPage($pageName); |
| 19 | 19 | |
| 20 | 20 | $perPage = $perPage ?: $this->model->getPerPage(); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | { |
| 33 | 33 | return array_merge( |
| 34 | 34 | parent::args(), |
| 35 | - $this->modelSchema->getLookupFields()->map(function (Field $field) { |
|
| 35 | + $this->modelSchema->getLookupFields()->map(function(Field $field) { |
|
| 36 | 36 | return $field->getType(); |
| 37 | 37 | })->toArray() |
| 38 | 38 | ); |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $input = $args->input->toArray(); |
| 50 | 50 | $model = $this->findOrFail($args); |
| 51 | 51 | |
| 52 | - return DB::transaction(function () use ($input, $model) { |
|
| 52 | + return DB::transaction(function() use ($input, $model) { |
|
| 53 | 53 | $modelSchema = $this->registry->getSchemaForModel($model); |
| 54 | 54 | |
| 55 | 55 | return $modelSchema->updateIfAuthorized($input); |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $type = $this->registry->ID()->list(); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - return $this->modelSchema->getLookupFields()->map(function (Field $field) { |
|
| 59 | + return $this->modelSchema->getLookupFields()->map(function(Field $field) { |
|
| 60 | 60 | return $field->getType(); |
| 61 | 61 | })->merge(['input' => $type])->toArray(); |
| 62 | 62 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | $pivotAccessor = $relation->getPivotAccessor(); |
| 78 | 78 | $pivotSchema = $this->getPivotModelSchema(); |
| 79 | 79 | |
| 80 | - $input->map(function ($input) use ($pivotSchema, $relation, $pivotAccessor, $model) { |
|
| 80 | + $input->map(function($input) use ($pivotSchema, $relation, $pivotAccessor, $model) { |
|
| 81 | 81 | $key = $input[$model->getKeyName()] ?? $input; |
| 82 | 82 | $pivotWhere = $input[$pivotAccessor] ?? []; |
| 83 | 83 | |
@@ -95,13 +95,13 @@ discard block |
||
| 95 | 95 | $query->wherePivot($relation->getRelatedPivotKeyName(), $key); |
| 96 | 96 | |
| 97 | 97 | return $query; |
| 98 | - })->map(function (Relations\BelongsToMany $query) use ($relation, $modelSchema) { |
|
| 99 | - $query->each(function (Model $related) use ($modelSchema) { |
|
| 98 | + })->map(function(Relations\BelongsToMany $query) use ($relation, $modelSchema) { |
|
| 99 | + $query->each(function(Model $related) use ($modelSchema) { |
|
| 100 | 100 | $modelSchema->authorizeToDetach($related); |
| 101 | 101 | }); |
| 102 | 102 | |
| 103 | 103 | return $query; |
| 104 | - })->each(function (Relations\BelongsToMany $query) use ($relation) { |
|
| 104 | + })->each(function(Relations\BelongsToMany $query) use ($relation) { |
|
| 105 | 105 | $query->detach(); |
| 106 | 106 | }); |
| 107 | 107 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | return $this->modelSchema->getLookupFields() |
| 50 | - ->map(function (Field $field) { |
|
| 50 | + ->map(function(Field $field) { |
|
| 51 | 51 | return $field->getType(); |
| 52 | 52 | }) |
| 53 | 53 | ->merge(['input' => $type]) |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | $input = $args->input->toArray(); |
| 77 | 77 | $model = $this->findOrFail($args); |
| 78 | 78 | |
| 79 | - return DB::transaction(function () use ($input, $model) { |
|
| 79 | + return DB::transaction(function() use ($input, $model) { |
|
| 80 | 80 | $modelSchema = $this->registry->getSchemaForModel($model); |
| 81 | 81 | |
| 82 | 82 | $relation = $this->getRelation($model); |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | { |
| 33 | 33 | $input = $args->input->toArray(); |
| 34 | 34 | |
| 35 | - return DB::transaction(function () use ($input) { |
|
| 35 | + return DB::transaction(function() use ($input) { |
|
| 36 | 36 | return $this->getModelSchema()->createIfAuthorized($input); |
| 37 | 37 | }); |
| 38 | 38 | } |