Giter Club home page Giter Club logo

Comments (5)

romanbican avatar romanbican commented on July 29, 2024

Hi,
you always need to have User object. If we're talking only about Blade, you can take advantage of view composers in Laravel 5.

Then you can have something like this:

@if ($currentUser->is('admin'))
    //
@endif

Instead of this:

@if (Auth::user()->is('admin'))
    // something
@endif

But if I understand correctly, you want something like this?

@role ('admin')
    // something
@endrole

@permission ('edit_articles')
    // something
@endpermission

Please, specify me your vision :-).

from roles.

romanbican avatar romanbican commented on July 29, 2024

There is also a very nice video about view composers in Laravel 5. Have a look!

from roles.

UnrulyNatives avatar UnrulyNatives commented on July 29, 2024

This solution would be amazing:

@role ('admin')
    // something
@endrole

The below made me perfectly happy:

@if (Auth::user()->is('admin'))
   // something
@endif

What I was unable to do in my L4 solution was using multiple conditions. I just used ||
Can you give me an example of a syntax for sth like this:

 @if (Auth::user()->is('admin') || Auth::user()->is('Developer'))

desired solution would be sth like this:

@if (Auth::user()->is('Admin','Developer') 

Generally I would add more complicated examples in the readme.md file.

After you answer I will prepare a pull request with all working examples you have provided. My pleasure.

from roles.

romanbican avatar romanbican commented on July 29, 2024

There is a way to check for multiple roles or permissions in one condition in my package.

if ($user->is('admin|moderator')) // or $user->is('admin, moderator') or $user->is(['admin', 'moderator'])
{
    // if user has at least one role
}

if ($user->is('admin|moderator', 'all')) // or $user->is('admin, moderator', 'all') or $user->is(['admin', 'moderator'], 'all')
{
    // if user has all roles that we check for
}

The same syntax applies to permissions.

Later today, I'll be working on this syntax for Blade:

@role ('admin')
    // something
@endrole

from roles.

romanbican avatar romanbican commented on July 29, 2024

New release is out. Check it out. There are some changes.

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.