Routing in Laravel

 In this tutorial you will learn about laravel routing,we will learn how to create route in laravel like post,get,delete and ect.
Routing helps to create request URL for application.Inside the laravel we use web.php and api.php for creating routing.

Route Syntex:
Route::get(‘/URL’, [Controller::class, ‘function’]);
Route::post(‘/URL’, [Controller::class, ‘function’]);
Route::put(‘/URL’, [Controller::class, ‘function’]);
Route::patch(‘/URL’, [Controller::class, ‘function’]);
Route::delete(‘/URL’, [Controller::class, ‘function’]);
Route::options(‘/URL’, [Controller::class, ‘function’]);

Create Laravel application using below command

composer create-project --prefer-dist laravel/laravel routedemo

Default route:

Route::get('/', function () {
    return view('welcome');
});

Route with Controller Method:

use App\Http\Controllers\Controller; //call controller class

Route::get('test' , [Controller::class,'index']); //create URL

Create function in Controller

 function index(){
        die("Its working");
    }

Run application

php artisan serve

Access URL

http://127.0.0.1:8000/test

Leave a Reply

Your email address will not be published. Required fields are marked *