CRUD with Eloquent
Create, read, update, and delete records using Eloquent methods.
Create — save()
Create a model instance, set attributes, and call save().
<?php
$post = new Post();
$post->title = "Hello World";
$post->body = "My first post";
$post->save(); // INSERT INTO posts ...Create — create()
Model::create() inserts a row in one line using mass assignment. Requires $fillable to be set.
<?php
$post = Post::create([
"title" => "Hello World",
"body" => "My first post",
"user_id" => auth()->id(),
]);