Laravel5.2 has no effect on backend user ACL permission management

Source: Internet
Author: User
In the Laravel5.1ACL tutorial, according to the above tutorial, if the user table uses the Default user table, everything is smooth, but my ultimate goal is to manage permissions in the admin table in the background, so I changed all the users in the tutorial to admin. At this time, a problem occurred. In blade, @ can (& #039; edit-po... laravel5.1 ACL tutorial

According to the above tutorial, if the user table uses the Default user table, everything is smooth, but my ultimate goal is to manage permissions in the admin table in the background, so I changed all the users in the tutorial to admin. At this time, a problem occurred. In blade@can('edit-post')And@can('delete-post')All failed

So I switched to the Controller.
        $admin = Auth::guard('admin')->user();        if($admin->can('edit-post')){            echo 1;        }

1, yeah!

So I thought about whether it was in the template.canIs the user table retrieved? So Iauth.phpDefaultguardChangeadmin

    'defaults' => [        'guard' => 'admin',        'passwords' => 'users',    ],

Successful! Yeah!
Okay, the problem is coming. I don't want to change it.auth.phpMediumguardIn the template.canIs the user of the admin table determined?

Reply content:

Laravel5.1 ACL tutorial

According to the above tutorial, if the user table uses the Default user table, everything is smooth, but my ultimate goal is to manage permissions in the admin table in the background, so I changed all the users in the tutorial to admin. At this time, a problem occurred. In blade@can('edit-post')And@can('delete-post')All failed

So I switched to the Controller.
        $admin = Auth::guard('admin')->user();        if($admin->can('edit-post')){            echo 1;        }

1, yeah!

So I thought about whether it was in the template.canIs the user table retrieved? So Iauth.phpDefaultguardChangeadmin

    'defaults' => [        'guard' => 'admin',        'passwords' => 'users',    ],

Successful! Yeah!
Okay, the problem is coming. I don't want to change it.auth.phpMediumguardIn the template.canIs the user of the admin table determined?

After reading the source code, it does not seem to support it !!!

    /**     * Compile the can statements into valid PHP.     *     * @param  string  $expression     * @return string     */    protected function compileCan($expression)    {        return "
  ";    }
    /**     * Determine if the given ability should be granted for the current user.     *     * @param  string  $ability     * @param  array|mixed  $arguments     * @return bool     */    public function check($ability, $arguments = [])    {        try {            $result = $this->raw($ability, $arguments);        } catch (AuthorizationException $e) {            return false;        }        return (bool) $result;    }    

The template can be written like this, but it is very long. I saved the if content to a public function.

@if(Gate::forUser(Auth::guard('admin')->user())->allows('$priv'))@endif 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.