laravel的resource route中隐藏着一个小技巧,就是.在url中的使用,如:
Route::resource('clients.accounts', 'AccountController', ['only' => ['index', 'show']]);
其对应的url是/clients/{client_id}/accounts/{account_id}和/clients/{client_id}/accounts/,这个技巧很有用。
推荐:laravel教程
控制器源码是:
namespace App\Http\Controllers; class AccountController extends Controller { public function index($client_id) { return $client_id; } public function show($client_id, $account_id) { return $client_id . '/' . $account_id; } }
相关推荐:PHP视频教程:https://www.php.cn/course/list/29/type/2.html
以上就是Laravel之Resource Route的点语法小技巧的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号