#How to add attributes to model? (Can't find in documentation)
15 messages · Page 1 of 1 (latest)
What do you mean, add attributes?
Like the basics: [ModelName.name, ModelName.dob, etc.] - how do I define the properties of the Model/DB Table?
You don’t. Eloquent is an ORM. Whatever columns are in the corresponding database table will automatically be made available as properties on the Eloquent model.
So if you have a column named foo_bar in the database table, you will be able to access the value of that column via $model->foo_bar
ah, so you generate the database tables first
then you just tell Larvel to use the schema?
I'm use to having to define it in the model Class then run some sort of migrations to create the db/table as needed
Yeah, migrations are separated from Eloquent models.
So you’d create your tables via migrations.
You can generate both the migration file and the Eloquent model class with php artisan make:model Foo -m
The -m option will create the migration file. There are other options too for creating things like a factory, a seeder, etc.
So I have a Model that was generated from the CLI tool.
class Children extends Model { use HasFactory; }
How do I tell Laravel that I want Children to have "name" and "date of birth"?
one as a string and one as a date?
Read the docs thoroughly and/or follow https://bootcamp.laravel.com/ and you wouldn't need to ask this question