I created a Model Account
with accountgroup_id
which refer from Account_group
Model. Then I call it from route
like this
Route::get('test', function () {
return \App\Account::get()->account_group;
});
Account Model has belogsto Relationship with Account_group
class Account extends Model
{
protected $fillable = ['accountgroup_id', 'accountno', 'accountname','address','contactno'];
public function account_group()
{
return $this->belongsTo('App\Account_group');
}
}
Account_group Model has hasMany relationship with Account
class Account_group extends Model
{
protected $fillable =['name','under'];
public function account()
{
return $this->hasMany('App\Account','accountgroup_id');
}
}
But after calling the route; I got following error.
Undefined property: Illuminate\Database\Eloquent\Collection::$account_group
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire