Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
How can i manage controller methods as per user role in laravel?
public function __construct()
{
    $this->middleware('roles:Author')->only(['index','show','create']);
    $this->middleware('roles:User')->only(['index','show']);
}

In my controller i want access methods as per users role for e.g if user role is admin then he has to access all methods of controller, if user role is Author then he has access of index,create and show method and if role is User then he has only access of index and show method.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can take a look at Gates (docs).

In your App\Providers\AuthServiceProvider add:

Gate::define('create-post', function ($user) {
    return $user->isAuthor(); //Here you should check the users role
});

And then in your controller's method create():

if (Gate::allows('create-post')) {
    // The current user can create posts...
}

The other two methods: index() and show() are available to both roles so there's no action required.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!