Giter Club home page Giter Club logo

Comments (4)

romanbican avatar romanbican commented on July 29, 2024

Well, in Laravel 5.1, there will be middleware parameters. So it will be really simple.

https://d1zj60nuin5mrx.cloudfront.net/media/2015/02/24125618/middleware-parameters.png

from roles.

zoranlorkovic avatar zoranlorkovic commented on July 29, 2024

I'm also interested in this option.
What is best solution before Laravel 5.1 goes out?

from roles.

romanbican avatar romanbican commented on July 29, 2024

Well, I think you must have middleware for every role.

from roles.

interphased avatar interphased commented on July 29, 2024

I had a project that I needed to do this with and found it easy to set it up where it would redirect a response if you were not a certain role, and then use them one after the other. So I have redirectIfNotAdmin, redirectIfNotApplicant, etc.

public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('admin', ['except' => ['index', 'show']]);
        $this->middleware('applicant', ['only' => ['something', 'somethingElse']]);
    }
class RedirectIfNotAdmin {
    public function handle($request, Closure $next)
    {
        if (Auth::user()->is('admin'))
        {
            return $next($request);
        }

        return redirect()->route('dashboard')
            ->with('flash_message', 'Sorry, you do not have enough privileges to view that page.');
    }
}
class RedirectIfNotApplicant {
    public function handle($request, Closure $next)
    {
        if (Auth::user()->is('applicant.*'))
        {
            return $next($request);
        }

        return redirect()->route('dashboard')
            ->with('flash_message', 'Sorry, you do not have enough privileges to view that page.');
    }

Works for me until Laravel 5.1 comes out.

from roles.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.