aishahyaacob
8 months ago

trying to get a property 'name' of non-object

Posted 8 months ago by aishahyaacob

i try to register,error occur but it sill connect to database

the error https://imgur.com/a/uYCz4jG

this is my user.php

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Http\Controllers\Auth;
//use Illuminate\Support\Facades\Auth;

class User extends Authenticatable
{
    use Notifiable;

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

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function isAdmin() {

        if($this->role->name == 'Admin'){

            return true;
        }
        return false;
    }

    public function isStudent() {

        if($this->role->name == 'Student'){

            return true;
        }
        return false;
    }

    public function role() {
        return $this-> belongsTo ('App\Role');
    } 

    public function questionAnswer()
    {
        return $this->hasMany('App\QuestionAnswer');
    }

    // Check if current user is admin
//    public function isAdmin(){
//        if(Auth::user()->role_id==1){
//            return true;
//        }
//
//        return false;
//    }
}

Please sign in or create an account to participate in this conversation.