How To Get URL Segment In Laravel?

How to Get URL Segment in Laravel?

By Hardik Savani April 16, 2024 Laravel

Hi Friends,

In this quick guide, we will teach you how to get url segment in laravel. I would like to show you laravel get url segment in view. Here you will learn laravel get url segment in controller. I would like to share with you get url segment in laravel blade. you will do the following things for get last url segment in laravel.

You can use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 versions.

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.

Laravel Get URL Segment in Blade File:

<!DOCTYPE html>

<html>

<head>

<title>how to get url segment in laravel - ItSolutionStuff.com</title>

</head>

<body>

{{ Request::segment(1) }}

{{ request()->segment(1) }}

</body>

</html>

Laravel Get URL Segment in Controller File:

Read Also: How to use Carbon in Laravel Blade or Controller File?

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PostController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index(Request $request)

{

$segment = $request->segment(1);

dd($segment);

}

}

I hope it can help you...Tags: LaravelHardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube← Previous Post

How to Get Current Route Name in Laravel?

Next Post →

How to Get Last Executed Query in Laravel?

More Posts You'll Love

How to Call Controller Function in Blade Laravel?

Laravel Call Function from Same Controller Example

Laravel Ajax DELETE Request Example Tutorial

Laravel nl2br Blade Directive Example

Laravel - How to Check If Array is Empty in Blade?

Laravel Ajax Request with Validation Example

How to Create Resource Controller in Laravel?

Laravel Create Bootstrap Contact US Form Example

How to Check Request is Ajax or Not in Laravel?

How to Get Current Controller Name in View Laravel?

How to Check Request Method is GET or POST in Laravel?

Ajax - Cross-Origin Request Blocked in Laravel?

YouTube

Join My YouTube Channel!Laravel 12 Videos Laravel Livewire 3 CourseSubscribe NowPopular Posts

  • Laravel Model Creating Event Example
  • How to create 404 error page in Laravel 5.8?
  • Laravel 9 Restrict User Access From IP Address Tutorial
  • Laravel Docker #14 - Install phpMyAdmin with MySQL Database
  • Laravel 11 Authentication using Jetstream Tutorial
  • How to Check Database Connection in Laravel?
  • Laravel 10 Custom Validation Rule Example
  • Laravel 8 Change Date Format Examples
  • Laravel 11 Send Email with Attachment Example
  • How to Send Mail in PHP Laravel?
Categories
  • PHP
  • Laravel
  • Javascript
  • Bootstrap
  • HTML
  • CSS
  • jQuery
  • MySql
  • Git
  • Wampserver
  • Installation
  • Elasticsearch
  • Ubuntu
  • .htaccess
  • JSON
Recent Posts
  • Laravel 12 - Socialite Login with Microsoft Account Example
  • Laravel Docker #15 - Push Docker Image to DockerHub
  • Laravel Docker #14 - Install phpMyAdmin with MySQL Database
  • Laravel Docker #13 - Install Adminer and MySQL Database
  • Laravel Docker #12 - Setup Environment Variables for Production

Từ khóa » How To Use Segment In Laravel