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
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.
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.
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));
$request->id; You can get id from POST method like this. public function getDetail(Requests $rq){ $product = Product::where('id',$rq->id)->get(); } .
Try this
{{ Request::segment(1) }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With