0% found this document useful (0 votes)
4 views

Lecture 3

Laravel Notes

Uploaded by

waver58650
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lecture 3

Laravel Notes

Uploaded by

waver58650
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Controllers :-

===============
1. In laravel controller act as a directing traffic between Views and Models.

2. Controller is basically the central unit here we can write logic, call database
data,
call models , and also pass the view from the controller.

3. Create a controller :-
php artisan make:controller <controller_name>

php artisan make:controller HomeController

4. Controller name should be start with the capital letter.

5. Now Go to the app directory then http then controller.

6. We can create a function with the public private and protected access specifier,
by default this is
the public.

Example :- HomeController
--------------------------
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller


{
//index function
public function index()
{
return "Home Controllers";
}
}

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

Example :- web.api
------------------

use App\Http\Controllers\HomeController;

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

You might also like