---
title: 'How to Set Default Values in Laravel Eloquent Models'
source: 'https://youtube.com/watch?v=Z0-x-chXGNI'
video_id: 'Z0-x-chXGNI'
date: 2026-08-14
duration_sec: 52
---

# How to Set Default Values in Laravel Eloquent Models

> Source: [How to Set Default Values in Laravel Eloquent Models](https://youtube.com/watch?v=Z0-x-chXGNI)

## Summary

This video explains how to set default values for database fields in Laravel, comparing the traditional migration approach with the Eloquent model's `$attributes` property. It highlights the flexibility of defining defaults in code rather than at the database level.

### Key Points

- **Setting Defaults in Migrations** [00:00] — You can set default values for fields in Laravel migrations using `default(false)`, `default('status')`, or `default(number)`, which applies at the database level.
- **Eloquent Model Attributes** [00:12] — Laravel's Eloquent models support an `$attributes` property to define default values that are automatically set when creating a new model instance, as shown in the official documentation.
- **Example of Eloquent Defaults** [00:24] — The video shows a code example where an array of key-value pairs is provided in the model to set defaults, mirroring the migration approach but at the application level.
- **Advantage of Code-Level Defaults** [00:41] — Defining defaults in Eloquent allows you to change them without altering the database schema, offering greater flexibility for future updates.

### Conclusion

Using Eloquent's `$attributes` property is a practical alternative to database-level defaults, enabling easier maintenance and code-driven configuration.

## Transcript

In Laravel database, if you want to set the default value for any field, you can do that in migrations, like this, providing default false, or default status, or default number. And that would be set
on the database level. But did you know you can do the same thing in Eloquent model? And here's the documentation. You can provide attribute values with attributes property. This is the
example from the docs. So you specify attributes values, which would be automatically set when you create a new model object. So the same example in migrations, if you want to do that on eloquent level in the code, would look something like this. So you just provide array of key and value pairs.
The advantage of doing that is that if you want to change the default value, you can do that in the code without changing the database. For more Laravel tips and longer tutorials, subscribe to my channel Laravel Daily.
