In this episode, we dive into working with models in Laravel. Now that our database is all set up, it’s time to see how Eloquent models make it way easier to interact with your data. We start by creating a basic User
model and learn how models are linked to database tables automatically. (Hint: Laravel just pluralizes the model name to figure out what table to use, but you can override that if you want.)
We switch our code from manually accessing the database to using the model, which is a huge productivity boost. You’ll also see how to configure fillable fields, protect attributes, and even mass assign data when creating new users. Along the way, we bump into the need for the created_at
and updated_at
fields—Eloquent expects them by default for tracking when records are created or updated.
Lastly, we touch on querying models, filtering results (like getting users with a specific name), and mention how you can go even further—like paginating, or setting up relationships later on. If you’re new to Eloquent, this episode is a gentle but practical step into using models the Laravel way.