Allow route model binding of trashed models

This commit is contained in:
Jonathan Reinink 2021-05-11 19:21:54 -04:00
parent 4bd372d7a6
commit eb00e058d2
3 changed files with 15 additions and 0 deletions

View File

@ -11,6 +11,11 @@ class Contact extends Model
use HasFactory;
use SoftDeletes;
public function resolveRouteBinding($value, $field = null)
{
return $this->where($field ?? 'id', $value)->withTrashed()->firstOrFail();
}
public function organization()
{
return $this->belongsTo(Organization::class);

View File

@ -11,6 +11,11 @@ class Organization extends Model
use HasFactory;
use SoftDeletes;
public function resolveRouteBinding($value, $field = null)
{
return $this->where($field ?? 'id', $value)->withTrashed()->firstOrFail();
}
public function contacts()
{
return $this->hasMany(Contact::class);

View File

@ -19,6 +19,11 @@ class User extends Authenticatable
'email_verified_at' => 'datetime',
];
public function resolveRouteBinding($value, $field = null)
{
return $this->where($field ?? 'id', $value)->withTrashed()->firstOrFail();
}
public function account()
{
return $this->belongsTo(Account::class);