Inserting & Updating Related Models (The Create Method)
https://viblo.asia/p/eloquent-relationships-in-laravel-phan-3-MJykjmxyePB
Ngoài save và saveMany methods, bạn có thể sử dụng create method, mà chấp nhận 1 mảng các thuộc tính, tạo ra 1 model và chèn nó vào cơ sở dữ liệu. Một lần nữa, sự khác biệt giữa save và create là save chấp nhận một thể hiện của Eloquent model đầy đủ trong khi create chấp nhận 1 mảng PHP:
$post = App\Post::find(1);
$comment = $post->comments()->create([
'message' => 'A new comment.',
]);PreviousInserting & Updating Related Models (The Save Method)NextInserting & Updating Related Models (Belongs To Relationships)
Last updated
Was this helpful?