lundi 1 mai 2017

Trying to get property of non-object Laravel 5.3, profile.blade.php.

I am trying to show the users profile information who are logged in,I have two tables one is Message and other one is User, when user login it see his\her profile, but there is an error.

profile.blade:

<table class="table table-bordered">
    <thead>
        <tr>
            <th>
                Name
            </th>
            <th>
                Email
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach($users as $usr)
        <tr>
            <td>
                
            </td>
            <td>
                
            </td>
        </tr>
        @endforeach
    </tbody>

Controller:

public function GetUserInfo($id){
    $user = DB::table('users')
        ->join('messages', 'messages.user_id', '=', 'users.id')
        ->where('users.id', '=', $id)
        ->get();
    if($user->count()){
        $user = $user->first();
        return view('profile')->with('users',$user);
    }
}

Model:

    class Messages extends Model
{
    protected $table = 'messages';
    protected $fillable = [
        'message','user_id'
    ];

    public function user()
    {
        return $this->hasOne('App\User', 'id', 'user_id');
    }
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2qlEjzN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire