Try using neo4j with Laravel ② Try to support Login with neo4j

Sep 10, 2020 PHP Laravel neo4j

* The model file is moved to app / Models.

② Try to support the login function

1) Enable login function

Execute the following command in the project

php artisan make: auth

2) Change User.php

<? php

namespace App \ Models;

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

use Illuminate \ Auth \ Authenticatable;
use Illuminate \ Auth \ Passwords \ CanResetPassword;
use Illuminate \ Foundation \ Auth \ Access \ Authorizable;
use Illuminate \ Contracts \ Auth \ Authenticatable as Authenticatable Contract;
use Illuminate \ Contracts \ Auth \ Access \ Authorizable as AuthorizableContract;
use Illuminate \ Contracts \ Auth \ CanResetPassword as CanResetPasswordContract;

use Vinelab \ NeoEloquent \ Eloquent \ Model as NeoEloquent;

class User extends NeoEloquent implements
    Authenticatable Contract,
    Authorizable Contract,
    CanResetPasswordContract
{
    use Notifiable, Authenticatable, Authorizable, CanResetPassword;

    protected $ label ='User';
    / **
     * 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',
    ];;
}

【Explanation】 Change inheritance source Originally the User class inherits from the Laravel framework Authenticatable, but since it is not derived from NeoEloquent I am rewriting it here. An error will occur if the model class is not derived from NeoEloquent.

use Illuminate \ Auth \ Authenticatable; use Illuminate \ Auth \ Passwords \ CanResetPassword; use Illuminate \ Foundation \ Auth \ Access \ Authorizable; use Illuminate \ Contracts \ Auth \ Authenticatable as Authenticatable Contract; use Illuminate \ Contracts \ Auth \ Access \ Authorizable as AuthorizableContract; use Illuminate \ Contracts \ Auth \ CanResetPassword as CanResetPasswordContract;

use Vinelab \ NeoEloquent \ Eloquent \ Model as NeoEloquent;

class User extends NeoEloquent implements Authenticatable Contract, AuthorizableContract, CanResetPasswordContract

Label settings By setting this, the label of the inserted data will be User. If not set, it will be AppModelsUser.

protected $ label ='User’;