Database Eloquent ORM Inserting / Saving Data

use App\Models\Post;

/*
|--------------------------------------------------------------------------
| ELOQUENT ORM (Object Relational Model)
|--------------------------------------------------------------------------
*/

Route::get('/basicinsert', function(){
    $post = new Post;
    $post->title = 'New Eloquent title insert';
    $post->content = 'Wow Eloquent is really cool';
    $post->save();
});

Route::get('/basicinsert2', function(){
    $post = Post::find(2);
    $post->title = 'New Eloquent title insert 2';
    $post->content = 'Wow Eloquent is really cool 2';
    $post->save();
});

The second one is really an update statement using find to find by ID, then updating the title and content.

Leave a Reply

Your email address will not be published.