How to Get URL Segment in Laravel?

28-Jul-2022

.

Admin

How to Get URL Segment in Laravel?

Today, I will let you know example of laravel get url segment. This tutorial will give you simple example of laravel url segment. This article will give you simple example of laravel get url segment view. you will learn get segment in laravel. Alright, let’s dive into the steps.

In this article, we will learn to get URL segments in controller and blade using the Laravel framework. We have the below route in the web.php that is located in the routes directory.

Example 1:


Get URL Segments OR Parameter in Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SegmentController extends Controller

{

/**

* Get a segment of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index(Request $request)

{

$segments = $request->segments();

dd($segments);

}

}

Example 2:

Get URL Segments OR Parameter in Blade File

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SegmentController extends Controller

{

/**

* Get a segment of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$segments = Request::segments();

dd($segments);

}

}

It will help you...

#Laravel 9

#Laravel