Home > Mobile >  Laravel 7 - Trait 'Laravel\Sanctum\HasApiTokens' not found
Laravel 7 - Trait 'Laravel\Sanctum\HasApiTokens' not found

Time:03-22

I am working with iframes and I am trying to compare the user's email with the teacher's email with eloquent. That would be the condition to list only the groups of that teacher, but it gives me this error:

Trait 'Laravel\Sanctum\HasApiTokens' not found

  • This is my function
    public function index($id)
        {
             $email = User::select('email')->where('id', $id)->get();
    
            $groups= DB::table('groups')
            ->join('teacher_group', 'grupo_profesor.idGrupo', '=', 'groups.idGrupo')
            ->join('teachers', 'teachers.idTeacher', '=', 'teacher_group.idTeacher')
            ->join('level_group', 'level_group.idGroup', '=', 'groups.idGroup')
            ->join('levels', 'levels.idLevel', '=', 'level_group.idLevel')
            ->join('courses', 'courses.idCourse', '=', 'levels.idCourse')
            ->join('programs', 'programs.idProgram', '=', 'courses.idProgram')
            ->where('teachers.email', '=', $email)
            ->paginate(10);
             
        return view('teacherGroups.index', compact('groups','email'));
        }

  • The sidebar button

<button  
onclick="crearTabAndIframe('TeacherGroups','teacherGroups');
Loadiframe('{{ url('Groups/Teacher/'.auth()->user()->id)}}','ifrmTeacherGroups')">

     <i >list</i> @lang('menu.List')

</button>

  • This is the index view

     @foreach($groups as $group)   
    <tr>
        <td >{{$group->idGroup}}</td>
    
        <td >{{$group->levelName}} {{$group->courseName}} {{$group->programName}}</td>
    
        <td >{{$group->teacher_name}}</td>
        
        <td >
            <div >
                <div >
                    <!--VIEW-->
                    <button onclick="seeGroup({{$group->idGroup}})" >
                        <i >remove_red_eye</i>
                    </button>
                </div>    
            </div>
        </td>
    </tr>
    @endforeach

  • And with the error it shows me this part of my model

    class User extends Authenticatable
    
    {
    
        use HasApiTokens, HasFactory, Notifiable;
    
     
    
        /**
    
         * The attributes that are mass assignable.
    
         *
    
         * @var string[]
    
         */
    
        protected $fillable = [
    
            'name',
    
            'email',
    
            'password',
    
        ];

CodePudding user response:

Try This, looks like you need to install sanctum

composer require laravel/sanctum

CodePudding user response:

I guess SanctumServiceProvider is not automatically registered in your application. To resolve your issue, you should add the service provider manually in config/app.php.

'providers' => [
    //...
    Laravel\Sanctum\SanctumServiceProvider::class,
]; 
  • Related