Laravel 8 多對(duì)多關(guān)系

2021-07-09 10:57 更新

像 [has many 關(guān)系] 一樣,可以使用 has 方法創(chuàng)建「多對(duì)多」關(guān)系:

    use App\Models\Role;
    use App\Models\User;

    $users = User::factory()
                ->has(Role::factory()->count(3))
                ->create(); 
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)