Categories: Laravel Framework - The PHP Framework For Web Artisans, Laravel Tutorial: Step by Step Guide to Building Your First Laravel Application - Techanical-Atom

Laravel Tutorials For Beginners Step By Step Guide – Part 25 min read

Laravel Tutorials For Beginners Step By Step Guide – Part 2
Reading Time: 4 minutes

Welcome to all of you. This is part 2 of the Laravel Tutorials For Beginners, if you haven’t read the Part-1 you can find it here. In this Laravel Tutorials, we are going to cover Model, Migration, And Controllers of the Laravel Application that will make the development easier for you. So let’s start with building an awesome app.

So first of all what we have created so far in the Part -1 of the
Laravel Tutorials is a basic Laravel application with Migrations migrated and default authentication system installed by which we can be able to Login, register, forget the password for the user and use the Auth::routes() of the laravel application.

Laravel front page with auth
Laravel front page with auth

Make Model And Migration

Now we are going to create the basic Model for the Order table. So just copy the following command in the command prompt by going into your laravel directory.

This will create a Model in the app/Order.php file witht the following content.

Now we are going to create the migration for the above Model and for that run the following command to make the migration for the Order table.

Now go to the database/migrations folder and look for the migration file there. By default , Laravel will add the current date into the name of the file so will find a file by name of somethng like this 2019_02_19_055804_create_table_order.php. Now open this file and the following line of code into the file.

After that run the following command to migrate the migration that we just created.

This will create the table in our database that we have specified in the .env file. Migration is just like the blueprint for your database table.

Creating Laravel Routes

All the laravel routes are found in the routes directory. The fileroutes/web.php defines routes that are for your web interface. These routes are assigned to the middlewareweb group, which provides features like session state and CSRF protection. Add the following routes in the
routes/web.php for the Order table for which we are going to create the basic CRUD actions.

Now as you can see we have used the OrderController as our controller but we haven’t created controller yet so let’s create OrderController using artisan CLI . Run the following command in the command prompt.

It will create a controller file called OrderController.php  The –resource flag at the end of the name of the controller, this controller will contain a method for each of the available resource operations. Navigate to the app/Http/Controllers/OrderController.php and add the following line of teh code there.

The above file controller contains a function for all the basic CRUD operation that you can implement on the Order table. Now all you need to do is fetch and sent the data to the controller and all these funtion will take crae for all the stuff.


Well, Congratulations now for completing the PART-2 of this series of  Laravel Tutorials For Beginners . In the third part of this series , we are going to create the views for all the actions and will add the proper validation on all the forms. I hope you have liked this article if you have any query you can just comment that below and we can discuss that in details. Cheers ! Happy Coding

All Rights Reserved @ Techanical-Atom
%d bloggers like this: