coderic
419
7
Laravel

Some of my laravel authorization abilities work and some don't.

Posted 3 years ago by coderic
namespace App\Policies;

use App\User;
use App\Course;

class MyCoursesPolicy
{
    /**
     * Create a new policy instance.
     *
     * @return void
     */

    public function is_Admin(User $user){
        // abort(403);
        return $user;
        if( $user->isAdmin() ){
            return true;
        }
    }

    public function update_course_attributes(User $user, Course $course){
        if( ($user->hasRole('instructor') && $course->users->get($user->id) ) || $user->isAdmin() ){
            return true;
        }
    }

}

so update_course_attributes works but is_Admin does not work. I don't know how to troubleshoot this... I've tried to return the $user object in is_Admin but it doesn't work. I'm using it like this:


    if(Gate::check('is_Admin', $this->user)){
      return "you're an admin ";
    } else {
      return "you're no admin ";
    }

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.