Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access URL segment(s) in blade in Laravel 5?

I have a url : http://localhost:8888/projects/oop/2

I want to access the first segment --> projects

I've tried

<?php echo $segment1 = Request::segment(1); ?>

I see nothing print out in my view when I refresh my page.


Any helps / suggestions will be much appreciated

like image 983
code-8 Avatar asked Aug 05 '15 12:08

code-8


People also ask

How do I get Uri segment in laravel blade?

Get a Segment from Current URL in Laravel If you need to only get a segment from the current URL in Laravel, use the segment() method from the Request() class. Pass the number of the segment to get as the first argument.

How do I find my URL in blade?

To get the current URL you can call the "url()" function and then chaining it with the "current()" function which will return the current page URL. Do note that when using this method you can get the URL path value and from the result, you can determine whether to show or hide values to the user.

How do you find the segment of a URL?

Use the following code to get URL segments of the current URL. It returns all the segments of the current URL as an array. $uriSegments = explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));

How can use URL ID in laravel?

$request->id; You can get id from POST method like this. public function getDetail(Requests $rq){ $product = Product::where('id',$rq->id)->get(); } .


1 Answers

Try this

{{ Request::segment(1) }} 
like image 188
Aniket Singh Avatar answered Sep 20 '22 01:09

Aniket Singh