0

I create a new role and tried to assign to the new user , it works perfectly but when i tried to do login with the new user credentials i got logged in but i got error. Please check the screenshot:

enter image description here

The error appears because it sets the role_id to null, even by choosing the permission created.Please check the screenshot:

enter image description here

 <?php

namespace TCG\Voyager\Traits;

use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use TCG\Voyager\Facades\Voyager;
use TCG\Voyager\Models\Role;

/**
 * @property  \Illuminate\Database\Eloquent\Collection  roles
 */
trait VoyagerUser
{
    public function role()
    {
        return $this->belongsTo(Voyager::modelClass('Role'));
    }

    /**
     * Check if User has a Role(s) associated.
     *
     * @param string|array $name The role to check.
     *
     * @return bool
     */
    public function hasRole($name)
    {
        if (!$this->relationLoaded('role')) {
            $this->load('role');
        }

        return in_array($this->role->name, (is_array($name) ? $name : [$name]));
    }

    public function setRole($name)
    {
        $role = Voyager::model('Role')->where('name', '=', $name)->first();

        if ($role) {
            $this->role()->associate($role);
            $this->save();
        }

        return $this;
    }

    public function hasPermission($name)
    {
        if (!$this->relationLoaded('role')) {
            $this->load('role');
        }

        if (!$this->role->relationLoaded('permissions')) {
            $this->role->load('permissions');
        }

        return in_array($name, $this->role->permissions->pluck('key')->toArray());
    }

    public function hasPermissionOrFail($name)
    {
        if (!$this->hasPermission($name)) {
            throw new UnauthorizedHttpException(null);
        }

        return true;
    }

    public function hasPermissionOrAbort($name, $statusCode = 403)
    {
        if (!$this->hasPermission($name)) {
            return abort($statusCode);
        }

        return true;
    }
}

Can someone help? Thanks.

  • Your assignment code isn't saving to the database. We need to see the code in order to help. – Option Oct 31 '17 at 10:17
  • @Option The problem is that this is a mistake of the one who made the voyager, already happened with other users, from what I saw in github. I asked the question here to see if anyone had already been through it. – Márcio André Oct 31 '17 at 10:25
  • Oookay... Generally not really what this place is for though. I'm sure people would be happy to help you repair it if you were to display the code though... ^_^ – Option Oct 31 '17 at 10:28
  • @Option Sure i put the code in the question :D – Márcio André Oct 31 '17 at 10:50

0 Answers0