mercredi 12 octobre 2016

BadMethodCallException in Builder.php line 2440: Call to undefined method Illuminate\Database\Query\Builder::getIdArray()

I'm creating role method in laravel, but when i start the page I have this error. If anyone has any idea you can share it. Thank you. Blablalbalblablablababasdadadadadadadadadadaadadadadadaadadasdqweqeqzxdadasdadadaadad

This is my User model

 <?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
    
   public function roles(){
       return $this->belongsTo(App\Role);
   }
   
   public function isEmployee(){
       return ($this->roles()->count()) ? true : false; 
   }
   
   public function hasRole($role){
       return (in_array($this->roles->pluck("names"), $role));
   }
    
   private function getIdInArray($array, $term){
       
       foreach ($array as $key => $value){
           if($value == $term){
               
               return $key;
           }
       }
       
       throw new UnexpectedValueException;
       
   }
   
   public function makeEmployee($title){
       $assigned_roles = array();
       
       $roles = Role::all()->pluck("name", "id");
       
       switch($title){
           case 'super_admin':
               $assigned_roles[] = $this->getIdArray($roles, 'create');
               $assigned_roles[] = $this->getIdArray($roles, 'update');
           case 'admin':
               $assigned_roles[] = $this->getIdArray($roles, 'delete');
               $assigned_roles[] = $this->getIdArray($roles, 'ban');
           case 'moderator':
               $assigned_roles[] = $this->getIdArray($roles, 'kickass');
               $assigned_roles[] = $this->getIdArray($roles, 'lemons');
               break;
           default:
               throw new \Exception("The employee status entered does not exist");
       }
       $this->roles()->sync($assigned_roles);
   }
   
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire