I want to get data from database that name is follower_id but when I try to get data I get error. And when I try with foreach I'm returning null I'm using database with relationships and I can get data if I type {{$follows}}
. On the other hand, if I type {{$follows->follower_id}}
I get this error:
Property [follower_id] does not exist on this collection instance.
So how can I solve this problem? I'm beginner in Laravel and database relationships by the way.
My controller is:
public function getProfile($username){
$follow = Follow::all();
$user = User::where('username', $username)->first();
if(isset($user)){
return view('design2.profile', ['user'=>$user,'follow'=>$follow]);
}else{
return redirect()->route('home');
}
}
My blade is:
<h6><span class="text-secondary"><strong>{{$follow->follower_id}} follower</strong></span></h6>
My follow model:
public $table = "follow";
protected $fillable = [
'follower_id',
'user_id',
];
public function user(){
return $this->belongsTo('AppModelsUser');
}
My user model:
protected $fillable = [
'name',
'email',
'username',
'password',
'info',
'twitter_name',
'instagram_name',
'photo'
];
public function follows(){
return $this->hasMany('AppModelsFollow');
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…