mardi 23 juillet 2019

BadMethodCallException Call to undefined method App\Student::generateToken()

ı want to make auth with different table instead of default user table and ı made with student table.

this is Student.php

<?php

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

class Student  extends Authenticatable
{

    use Notifiable;

    protected $table='students';
    protected  $fillable=['full_name','email', 'password'];

    protected $hidden = [
        'password', 'remember_token',
    ];

    public function getAuthPassword()
    {
        return $this->password;
    }
}

auth.php

 'defaults' => [
        'guard' => 'web',
        'passwords' => 'students',

    ],


  'guards' => [
 'students' => [
            'driver' => 'eloquent',
            'model' => App\Student::class,
        ],
        //this is last
        'students' => [
            'provider' => 'students',
            'table' => 'password_resets',
            'expire' => 60,
        ],
],

  'providers' => [

        'students' => [
            'driver' => 'eloquent',
            'model' => App\Student::class,
        ],


    ],

'passwords' => [

        'students' => [
            'provider' => 'students',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],

];

auth/RegisterController

<?php

namespace App\Http\Controllers\Auth;


use App\Student;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;


class RegisterController extends Controller
{



    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [

            'full_name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:students'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],


        ]);
    }




    protected function create(array  $data)
    {


        $api_token=str_random(60);
        return Student::create([

                'full_name' => $data['name'],
                'email' => $data['email'],
                 'api_token'=>$api_token,
                  'password'=>bcrypt($data['password']),
            ]

        );
    }
}

ı can make register well but when ı want to make login I am getting this error.

BadMethodCallException Call to undefined method App\Student::generateToken()

so please help me.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire