In this Laravel project tutorial we will learn to create model using Artisan.
Till now we have accomplished the following.
Eloquent is the default ORM (Object Relational Mapper) of Laravel.
For every database table we create a model which helps to interact with the table.
To create a model in Laravel we take help of the make:model command.
So, let's create a model for the todos table by running the following command in the terminal.
$ php artisan make:model Todo
On success we will get the following output.
Model created successfully.
By convention we name model in singular like Todo and it will interact with the database table have plural name like todos.
So, if your table name is lets say books (in plural) then by convention your model name must be Book (in singular).
On running the make:model command we will get a new file inside the app directory.
Since we named our model Todo so, a new file Todo.php was created inside the app directory with the following code.
class Todo extends Model
In the next tutorial we will play with the todos table using Tinker. It will be awesome.
Thanks for reading. See you in the next tutorial.
Have fun coding :-)
Have fun learning :-)
Copyright © 2014 - 2019 DYclassroom. All rights reserved.
rendered in 0.0223 sec