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...
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial