Skip to main content

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

Read more here

area17/twill

3925 stars
2 code files
View area17/twill on GitHub

src/AuthServiceProvider.php

Open in GitHub
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
 
class AuthServiceProvider extends ServiceProvider
{
//
public function boot()
{
Gate::define('list', function ($user) {
return $this->authorize($user, function ($user) {
return $this->userHasRole($user, [UserRole::VIEWONLY, UserRole::PUBLISHER, UserRole::ADMIN]);
});
});
 
Gate::define('edit', function ($user) {
return $this->authorize($user, function ($user) {
return $this->userHasRole($user, [UserRole::PUBLISHER, UserRole::ADMIN]);
});
});
 
Gate::define('reorder', function ($user) {
return $this->authorize($user, function ($user) {
return $this->userHasRole($user, [UserRole::PUBLISHER, UserRole::ADMIN]);
});
});
 
Gate::define('publish', function ($user) {
return $this->authorize($user, function ($user) {
return $this->userHasRole($user, [UserRole::PUBLISHER, UserRole::ADMIN]);
});
});
//
}
}

src/Http/Controllers/Admin/ModuleController.php

Open in GitHub
abstract class ModuleController extends Controller
{
public function __construct(Application $app, Request $request)
{
parent::__construct();
$this->app = $app;
$this->request = $request;
 
$this->setMiddlewarePermission();
//
}
 
protected function setMiddlewarePermission()
{
$this->middleware('can:list', ['only' => ['index', 'show']]);
$this->middleware('can:edit', ['only' => ['store', 'edit', 'update']]);
$this->middleware('can:duplicate', ['only' => ['duplicate']]);
$this->middleware('can:publish', ['only' => ['publish', 'feature', 'bulkPublish', 'bulkFeature']]);
$this->middleware('can:reorder', ['only' => ['reorder']]);
$this->middleware('can:delete', ['only' => ['destroy', 'bulkDelete', 'restore', 'bulkRestore', 'forceDelete', 'bulkForceDelete', 'restoreRevision']]);
}
//
}

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.