Question : add a controller method in laravel routes
Answered by : john-pinto
//adding a Controller's path with method in laravel route.
//say Controller is 'PagesController'
//create controller: in terminal: php artisan make:controller PagesController
// -> app/Http/Controller/PagesController.php
//use ....
//use ,..
class PagesController{ public function index(){ $data = [ 'title' => 'Home' ]; //for home.blade.php return('home', compact('data')); }
}
//create home.blade.php file in routes/
//->routes/home.blade.php
echo $data['title'];
//->routes/web.php Route::('/', 'App\Http\Controller\PagesController@index'); //using index() method
Source : | Last Update : Thu, 21 Jul 22