-
app/Exceptions/MissingModel.php
Open in GitHubuse Exception; class MissingModel extends Exception { public function __construct() { parent::__construct('Model is missing.'); } }
-
app/Services/ForRouteGate.php
Open in GitHubuse App\Exceptions\MissingModel; use App\Models\User; use App\Providers\AppServiceProvider; class ForRouteGate { // public function forOwner($user, $permissionName, $model) { if ($model === null) { throw new MissingModel(); } $ownerField = AppServiceProvider::OWNER_FIELD; if ($model->$ownerField === null) { return $user->hasPermission($permissionName); } return $user->isModelOwner($permissionName, $model); } }