Skip to content

Commit

Permalink
Allow route model binding of trashed models
Browse files Browse the repository at this point in the history
  • Loading branch information
reinink committed May 11, 2021
1 parent 4bd372d commit eb00e05
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/Models/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit eb00e05

Please sign in to comment.