From e576fdff93165b7f33da65b92c067cc432c9035b Mon Sep 17 00:00:00 2001 From: Daniel Polito Date: Tue, 23 Apr 2019 12:49:12 -0300 Subject: [PATCH] Improving Model --- app/Model.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/app/Model.php b/app/Model.php index caf850e..f0ae1c4 100644 --- a/app/Model.php +++ b/app/Model.php @@ -2,20 +2,19 @@ namespace App; -use Illuminate\Support\Facades\App; -use Illuminate\Database\Eloquent\Model as Eloquent; +use Illuminate\Database\Eloquent\Model as BaseModel; +use Illuminate\Database\Eloquent\SoftDeletes; -abstract class Model extends Eloquent +abstract class Model extends BaseModel { protected $guarded = []; - - public function getPerPage() - { - return 10; - } + + protected $perPage = 10; public function resolveRouteBinding($value) { - return $this->where('id', $value)->withTrashed()->first() ?? App::abort(404); + return in_array(SoftDeletes::class, class_uses($this)) + ? $this->where($this->getRouteKeyName(), $value)->withTrashed()->first() + : parent::resolveRouteBinding($value); } }