Viết lại sử dụng static thay thuộc tính \App\Address::create, $user->address()->create (ok)
https://app.gitbook.com/@c-i-ph-n-m-m-tr-n-ubuntu-c-n-thi/s/learn-lavarel/relationships-su-dung-hasone-ok
$user = factory(\App\User::class)->create();
// Cách 1:
\App\Address::create([
"user_id" => $user->id,
"country" => "Ha Nam 10"
]);
// Cách 2:
// $user->address()->create([
// "country" => "Ha Nam 9"
// ]);

PreviousRelationships sử dụng hasOne, belongsTo (ok)NextNói về trường hợp mặc định về phương thức trùng với tên bảng nó sẽ quyết định id (ok)
Last updated
Was this helpful?