Hello I'm trying get my objects on laravel like this.
But I'm getting this error.
PHP error: Undefined property: Illuminate\Database\Eloquent\Collection::$retails on line 18
Also this is my code.
public function index(){
$retails = Auth::user()->companies->retails->all();
return view('retails/retails', compact('retails'));
}
Company Model
class Company extends Model
{
public function retails(){
$this->hasMany(Retail::class);
}
}
Retail Model
class Retail extends Model
{
public function company(){
return $this->belongsTo(Company::class);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire