Laravel eloquent update record without loading from database



PHP Snippet 1:

DB::table('post')
            ->where('id', 3)
            ->update(['title' => "Updated Title"]);

PHP Snippet 2:

Post::where('id',3)->update(['title'=>'Updated title']);

PHP Snippet 3:

$post = new Post();
$post->exists = true;
$post->id = 3; //already exists in database.
$post->title = "Updated title";
$post->save();

PHP Snippet 4:

$post = Post::find($id);

PHP Snippet 5:

$post = Post::find(3);
$post->title = "Updated title";
$post->save();

PHP Snippet 6:

$affectedRows = Post::where("id", 3)->update(["title" => "Updated title"]);

PHP Snippet 7:

// Retrieve the Post by the attributes, or create it if it doesn't exist...
$post = Post::firstOrCreate(['id' => 3]);
// OR
// Retrieve the Post by the attributes, or instantiate a new instance...
$post = Post::firstOrNew(['id' => 3]); 

// update record
$post->title = "Updated title";
$post->save();