From eb00e058d2718909a21b27efc83d714cabc937dd Mon Sep 17 00:00:00 2001 From: Jonathan Reinink Date: Tue, 11 May 2021 19:21:54 -0400 Subject: [PATCH] Allow route model binding of trashed models --- app/Models/Contact.php | 5 +++++ app/Models/Organization.php | 5 +++++ app/Models/User.php | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/app/Models/Contact.php b/app/Models/Contact.php index 6619a4b..6842c29 100644 --- a/app/Models/Contact.php +++ b/app/Models/Contact.php @@ -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); diff --git a/app/Models/Organization.php b/app/Models/Organization.php index 7eade38..6ee084b 100644 --- a/app/Models/Organization.php +++ b/app/Models/Organization.php @@ -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); diff --git a/app/Models/User.php b/app/Models/User.php index 1c6fc2d..4dfaac6 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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);