From b25f2b72a0aab0fbb90c6c9dd204a442af60ebb3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 2 Apr 2019 17:43:17 +1100 Subject: [PATCH] Change to firstOrFail() for route model binding --- app/Models/Client.php | 2 +- app/Providers/RouteServiceProvider.php | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/Models/Client.php b/app/Models/Client.php index a875d12972b3..79ed5da1653f 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -37,7 +37,7 @@ class Client extends BaseModel 'shipping_country' ]; - protected $with = ['contacts', 'primary_contact', 'country', 'shipping_country']; + protected $with = ['contacts', 'primary_contact', 'country', 'shipping_country', 'company']; protected $casts = [ 'settings' => 'object' diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index d189e2d2c18a..56dcfc39a64a 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -30,52 +30,52 @@ class RouteServiceProvider extends ServiceProvider Route::bind('client', function ($value) { $client = \App\Models\Client::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail(); - $client->with('contacts', 'primary_contact','country'); + // $client->with('contacts', 'primary_contact','country'); return $client; }); Route::bind('invoice', function ($value) { - return \App\Models\Invoice::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + return \App\Models\Invoice::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail(); }); Route::bind('payment', function ($value) { - return \App\Models\Payment::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + return \App\Models\Payment::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail(); }); Route::bind('product', function ($value) { - return \App\Models\Product::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + return \App\Models\Product::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail(); }); Route::bind('company', function ($value) { - return \App\Models\Company::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + return \App\Models\Company::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail(); }); Route::bind('account', function ($value) { - return \App\Models\Account::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + return \App\Models\Account::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail(); }); Route::bind('client_contact', function ($value) { - return \App\Models\ClientContact::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + return \App\Models\ClientContact::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail(); }); Route::bind('expense', function ($value) { - return \App\Models\Expense::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + return \App\Models\Expense::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail(); }); Route::bind('invitation', function ($value) { - return \App\Models\Invitation::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + return \App\Models\Invitation::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail(); }); Route::bind('task', function ($value) { - return \App\Models\Task::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + return \App\Models\Task::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail(); }); Route::bind('tax_rate', function ($value) { - return \App\Models\TaxRate::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + return \App\Models\TaxRate::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail(); }); Route::bind('proposal', function ($value) { - return \App\Models\Proposal::where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); + return \App\Models\Proposal::where('id', $this->decodePrimaryKey($value))->firstOrFail(); });