内容简介:翻译自:https://stackoverflow.com/questions/37907191/get-last-part-of-current-url-in-laravel-5-using-blade
如何动态获取当前URL的最后一部分没有’/’?
例如:
www.news.com/foo/bar
得到 – >酒吧
www.news.com/foo/bar/fun
得到 – >开玩笑
在当前视图中放置函数或如何实现它的位置?
是您想要的信息的来源.您可以通过几种方式获取信息,其中大部分都涉及将某些内容传递给您的视图.我强烈建议不要在刀片中进行工作,因为这是控制器操作的用途.
将值传递给刀片
最简单的方法是使路由的最后一部分成为参数,并将该值传递给视图.
// app/Http/routes.php Route::get('/test/{uri_tail}', function ($uri_tail) { return view('example')->with('uri_tail', $uri_tail); }); // resources/views/example.blade.php The last part of the route URI is <b>{{ $uri_tail }}</b>.
避免路由参数需要更多的工作.
// app/Http/routes.php Route::get('/test/uri-tail', function (Illuminate\Http\Request $request) { $route = $request->route(); $uri_path = $route->getPath(); $uri_parts = explode('/', $uri_path); $uri_tail = end($uri_parts); return view('example2')->with('uri_tail', $uri_tail); }); // resources/views/example2.blade.php The last part of the route URI is <b>{{ $uri_tail }}</b>.
使用 request helper 在刀片中完成所有操作.
// app/Http/routes.php Route::get('/test/uri-tail', function () { return view('example3'); }); // resources/views/example3.blade.php The last part of the route URI is <b>{{ array_slice(explode('/', request()->route()->getPath()), -1, 1) }}</b>.
翻译自:https://stackoverflow.com/questions/37907191/get-last-part-of-current-url-in-laravel-5-using-blade
以上所述就是小编给大家介绍的《使用Blade获取Laravel 5中当前URL的最后一部分》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 使用JGit获取变更细节
- WebRTC 使用之 —— 使用 getUserMedia 获取视频流
- 使用ColorfulImg获取图片主题色!
- PowerShell 使用 WMI 获取信息
- 使用 PHP 获取网站 SSL 证书信息
- 使用 Docker CertBot 获取 SSL 证书
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
深入浅出MFC (第二版)
侯俊杰 / 华中科技大学出版社 / 2001-1 / 80.00元
《深入浅出MFC》分为四大篇。第一篇提出学习MFC程序设计之前的必要基础,包括Widnows程序的基本观念以及C++的高阶议题。“学前基础”是相当主观的认定,但作者是甚于自己的学习经验以及教学经验,其挑选应该颇具说服力。第二篇介绍Visual C++整合环境开发工具。此篇只是提纲挈领,并不企图取代Visual C++使用手册;然而对于软件使用的老手,此篇或已足以帮助掌握Visual C++整合环境......一起来看看 《深入浅出MFC (第二版)》 这本书的介绍吧!