Laravel Relation Has Many

[Solved] Laravel Relation Has Many | Php Frameworks Yii - Code Explorer | yomemimo.com
Question : laravel relation has many

Answered by : jrmew

// Post model
public function comments()
{ return $this->hasMany(Comment::class);
}
// Post controller
$comments = Post::find(1)->comments;

Source : https://laravel.com/docs/8.x/eloquent-relationships#one-to-many | Last Update : Tue, 18 May 21

Question : laravel create many relations

Answered by : hassan-elshazly-eida

$parentItem = ParentItem::first();
$items = array( new Item(['title' => 'test1','desc' => 'test1']), new Item(['title' => 'test2','desc' => 'test2'])
);
$parentItem->items()->saveMany($items)

Source : https://stackoverflow.com/questions/35212000/laravel-eloquent-relationship-create-multi | Last Update : Fri, 09 Dec 22

Question : laravel has many through relationship

Answered by : cooperative-crab-qq95wr7pe6oz

projects id - integer name - string
environments id - integer project_id - integer name - string
deployments id - integer environment_id - integer commit_hash - string

Source : https://laravel.com/docs/8.x/eloquent-relationships | Last Update : Sat, 31 Jul 21

Question : laravel has one of many relationship

Answered by : sore-seal-wuavpzzykeev

/** * Get the user's most recent order. */
public function latestOrder()
{ return $this->hasOne(Order::class)->latestOfMany();
}

Source : https://laravel.com/docs/8.x/eloquent-relationships#one-to-one | Last Update : Thu, 17 Jun 21

Answers related to laravel relation has many

Code Explorer Popular Question For Php Frameworks Yii