I need a little clarification.
This error message "Trying to get property of non-object" to what is referred to when using Eloquent? I'm going crazy. I am using a function:
public function squadra_post()
{
return $this->hasMany('Squadra','id_squadra');
}
that is the model that extends Eloquent Post. When the call:
<?php $squadra = Post::find($roles->id_squadra)->squadra_post; ?>
gives me the error that I mentioned before.
EDIT
his is the class post with their methods. What to give problems is "squadra_post ()" I need to extract the name of the team by id_squadra post content in table.
class Post extends Eloquent implements UserInterface, RemindableInterface
{
protected $table = 'post';
protected $primaryKey = 'id_post';
public $timestamps = false;
public function commenti()
{
return $this->hasMany('Commento','id_post');
}
public function apprezzamenti()
{
return $this->hasMany('Apprezzamenti','id_post');
}
public function squadra_post()
{
return $this->hasMany('Squadra','id_squadra');
}
}
This is the code of the class "squadra"
class Squadra extends Eloquent implements UserInterface, RemindableInterface
{
protected $table = 'squadra';
protected $primaryKey = 'id_squadra';
public $timestamps = false;
}
And finally, this is the code that gives me problems. That is what gives me the error: Trying to get property of non-object
@foreach($post['post'] as $roles)
@if($roles->id_squadra != 0)
$squadra = Post::find($roles->id_squadra)->squadra_post;
@foreach($squadra as $squadra_post)
{{ $squadra->nome }}
@endforeach
@endif
@endforeach