Laravel Get URL Segment Example Tutorial

Jul 28, 2022 . Admin


Hi friends,

In this tutorial we will go over the demonstration of laravel 9 get url segment. We will use laravel 9 url segment. We will look at example of laravel 9 get url segment view. we will help you to give example of get segment in laravel. Follow bellow tutorial step of get url segment in laravel.

Whenever you need to get current url segment then you can get using Request facade. I give you example one for using Request facade. so you can get segment from url and how you can see both example.

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