php - Laravel eloquent table structure -
i quite new laravel
, eloquent
world , i'm loving far, having trouble understating how structure tables , models in order me able crud data eloquents relationships. far have structured tables this:
users -----------------has_one------->onsite_teachers onsite_teachers -------has_many------>train_lines train_lines -----------has_many------>train_stations train_lines -----------belongs_to---->text_train_lines train_stations --------belongs_to---->text_train_stations
my question how best construct models me able crud using relationships. because have tried following no success:
$user = user::find(1); $user->onsite_teacher->train_lines()->save($data); $user->onsite_teacher->train_lines->train_stations()->save($data);
it looks query wrong
try this:
$user = user::find(1); $user->onsite_teacher()->first() ->train_lines()->save($data);
Comments
Post a Comment