Change to firstOrFail() for route model binding

This commit is contained in:
David Bomba 2019-04-02 17:43:17 +11:00
parent ef08afc240
commit b25f2b72a0
2 changed files with 13 additions and 13 deletions

View File

@ -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'

View File

@ -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();
});