Laravel Practice: Fundamentals

Till now  we have covered :
Laravel fundamentals that consists of
Little bit of blade templating engine


In route we route the link example:

Some route example including where method:

naming routes from edwin’s video:

Laravel Routing:


To create controller with predefined functions we need php artisan command

This command will create automatic controller file name ZakiLive.php in

folder with predefined function.

Link Controller With Routes

So, we can set in routes/web.php file and link with controller by below code:

here index is a function/method that is exist in with ZakiLive.php  controller file

Passing data to controller from route:
in route/web.php file

Now in ZakiLive.php controller file in index method/function we are getting the id, name from the url route so the code of this function below:

So when we are typing:

It is giving the output:
Hello! ID: 99name: jjfrom Zaki

Resources and Controllers:
By typing this in web.php route file:

Check we didn’t linked to any specific methods in ZakiLive controller file..This is the magic of resource function in laravel and then typing PHP artisan command from terminal we get:

So, from the above list if we type then it will return from create method available in ZakiLive.php controller file

so here it is I defined:

This is Create Method

Controller reference in official laravel docs:


Views available in laravel 5.4 in resources/views/dekho.blade.php

Now need to route the url to controller ZakiLive.php…so in this file the below code:

Now link the route/web.php file with controller file


Passing Data to View:

We can pass data from url to view through controller by using below code:
In Controller ZakiLive.php we need to write the below code:

in route we need to pass the url with id :

In views folder now we can create a blade formatted php file to display the passed data from url

View Data Without Controller(Passed data only from Route to View):

in views folder:
view/hello/greetings.bade.php file

Laravel View Reference:

 Master Layout with Blade Templating

for layout setup i am explaining here from routing to controller to blade templating from first to last(A-Z)

In routes/web.php add this line:

and now in controller file ZakiLive.php
add this line:

now in views folder create a folder “bladebladedekhao” then a file “appshow.blade.php”

in this file add some codes

check attentively that here @yield(‘content’) is declaring the section in <div> </div> and @yield(‘dhaka’) is defining the inside of <b> </b> section where <body> </body> section is defining by @yield(‘footer’) section

Now views/bladeshow.blade.php file we are going to write this code:

where extends is a blade syntax and it’s helping to include “appshow.blade.php” file to the bladeshow.blade.php file in views folder

@section(‘content’) is inherited part from the appshow file @endsection/@stop is closing the section gracefully 😀

{{id}} and {{pass}} variable is coming from the url by using below link:

Same we can do for contact page :
to do this in routes/web.php file we can do :

then in controller file ZakiLive.php:

Then in views/contact.blade.php file we can add this code:

and after typing the url we will get the output:


Some more blade features with 

For contact page we will assign manual variable in controller to send it to contact page. Let’s see: How we can do it:

Now in Contact page:

So Output will be like this:

if we change in controller like this:

It will show nothing but only contact page:
So Output will be like this:

if we change in controller like this:

It will show nothing but only contact page:
So output will be like this:

Reference for laravel blade engine:

Migrate Database and Dropping them:

Create database manually from phpmyadmin giving the name laravel_cms then in .env file we will set the database credentials like pass,username etc.
then we will type:

then in database/migration folder we will check some predefined files name for creating our own table with migration.
then we need to type in terminal about this:

It will create the file below like this:

Now to update this we can create this:

and it will change the mysql db and add “ghost” table in database that can be checkecd from phpmyadmin

now if we want to roll back/drop the database ghost that we created we need to just type this command:

then aftwer checking the database with php myadmin we will see that “ghost” table is not available there 🙂

if we again type

then ghost table will be back from the database

Adding Column to Existing Database and Dropping Them:

RAW SQL Query:

For inserting into database:

For Reading from the database:

Reading Slightly Difference:




Database Eloquent ORM:

Some example to see with database in route with Post ORM:


Order by in database:

Insert method:

ORM insert by find(specific_id_in_db)

Creating Data and Configuring mass Assignment:

In routes/web.php

Update ORM:

Delete with ORM:

Softdelete :

Force delete:

Eloquent Relationship:

One To One:

Create a table Ghost:


then go to phpmyadmin and add some data to the table “ghost”

then create a model with the help of ORM

in Amar model file:




Our main task is in:
routes folder where we can create naming routes for a page which plays role to redirect a page from web browser to view for the user using help of the PostsController.

Make a recipe for my working project:
In routes/web.php (aka routes.php) we need to add a line