In this video we are going to learn about a controller.
In laravel controller act as a directing traffic between Views and Models.
Controller is basically the central unit here we can write logic, call database data, call models , and also pass the view from the controller.
Lots of things that we can do from controller.
Alright now lets see how can we Create a Controller.
For that switch to the command prompt and here just type the command for creating a controller.

php artisan make:controller HomeController

Here HomeController is controller name.
Controller name should be start with the capital letter.
Now press enter Now HomeController has been created successfully.
Now switch to project.
and now Go to the app directory then http then controller.
and you can see here, HomeController.
Just open it.
Inside the HomeController you will see that some codes are written here by default.
Now inside this controller lets create a function here.
We can create a function with the public private and protected access specifier.
By default this is the public.
So just type here.

public function index()
{
return \"Hi, From HomeController\";
}

Now lets define a route for this controller.
So go to the web.php file and just create the route here.
so just write a here.

Route::get('/home', [HomeController::class, 'index'])->name('home.index');

Make sure you have import the HomeController on top as following.


use App\\Http\\Controllers\\HomeController;


Now lets check.
So switch to the browser.
Just go to the URL http://localhost:8000/home.
Now see here \"This is HomeController\".
Now lets see, how we can pass the parameters into the controller.
So for passing parameter we have to modify the route as well as controller method.
So let's modify the route.
So go to the web.php.
For passing the parameter just write here /{name}
Now open the Controller that is HomeController and just type here $name.
And here I print this.
Just type echo \"Hi \".$name.
Now let's check.
Switch to the browser.
And add any name here press enter.
Ok now see this, name is now showing here. if you want to make parameter optional.
Just add ? Sign with the parameter.
and $name=null in HomeController also.
Now parameter has become optional.
Lets check this.
First refresh the page.
Ok it goods it working.
Now remove the parameter.
It still working.
Alright , you can see that.
its working with parameter or without parameter.
So that's all about laravel Controller.