Eloquent ORM: Working with Data as Objects
Learn how to use Eloquent ORM to insert, read, update, and delete records easily.
Eloquent lets you treat database rows as PHP objects. ## Create a model ```bash php artisan make:model Post ``` ## Insert data ```php Post::create([ 'title' => 'My First Post', 'body' => 'Hello Laravel!' ]); ``` ## Fetch data ```php $posts = Post::all(); $post = Post::find(1); ``` ## Update and delete ```php $post->title = 'Updated'; $post->save(); Post::destroy(1); ``` ## How Eloquent works ```mermaid flowchart LR A[Controller] --> B[Eloquent Model] B --> C[(Database)] C --> B ``` In the next tutorial, we will map URLs to logic using routes and controllers.