Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

jcergolj/laravellte

216 stars
2 code files
View jcergolj/laravellte on GitHub

app/Exceptions/MissingModel.php

Open in GitHub
use Exception;
 
class MissingModel extends Exception
{
public function __construct()
{
parent::__construct('Model is missing.');
}
}

app/Services/ForRouteGate.php

Open in GitHub
use 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);
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.