Showing posts with label generate urls to named routes laravel. Show all posts
Showing posts with label generate urls to named routes laravel. Show all posts

Laravel Generate URLs to Named Routes Tutorial

Hi Guys,

In this blog, i will give you simaple example of generate urls to named routes in laravel. we are create examples of url to named route.

All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by the framework. The routes/web.php file defines routes that are for your web interface.

Example 1: Basic Url To Routes

Laravel provides a global route() function that gets the URL to a named route. The only one Parameter is the route name (string).

Simple example, it would look as routes/web.php file defines routes that are for your web interface:

Basic Route:
<?php
use App\Http\Controllers\HomeController;

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

or

This is achieved by chaining the name() method to the route definition:

Route::get('Home', function() {
    return view('home');
})->name('home');

Simple example, as it would look as an anchor tag within in a Blade template:

Basic url:
Simple url To route
Example: Single Parameter Url To Routes

Laravel provides a global route() function that gets the URL to a named route. The first Parameter is the route name (string). Depending on the route you’re trying to access you may also need to pass in an array of parameters as the second argument.

Example 2: Single Parameter Route:

Simple example, it would look as routes/web.php file defines routes that are for your web interface:

<?php
use App\Http\Controllers\PostsController;

Route::get('posts/{id}', ['PostsController::class','show'])->name('post');

Simple example, as it would look as an anchor tag within in a Blade template:

Link to Resource {{ $id }}

It will help you...