jeudi 28 février 2019

Trying to get property '' of non-object (View:

I am trying to fetch a user based on their corresponding District/ area by the ID stored in the user table,

I am able to fetch the result for District where as for the Area, I am getting error,

Trying to get property 'area_name' of non-object (View: user-index.blade.php)

User 

id | district_id | area_id | user_name

District

id | district_name

area

id | district_id | area_name

Controller

 $users = Users::simplePaginate(5);

        return view('user-index',compact('users'));

Model

User

public function districts(){
        return $this->belongsTo('App\Districts','district_id','id');
    }

    public function areas(){
        return $this->belongsTo('App\Area','area_id','id');
    }

blade

 @foreach ($users as $user)
                                -  I get result
                               - I get result
                               -- I get error 

@endforeach



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire