Laravel学习笔记之Resource Route的点语法小技巧

Laravel的Resource Route中隐藏着一个小技巧,就是.在url中的使用,如:

Route::resource('clients.accounts', 'AccountController', ['only' => ['index', 'show']]);

其对应的url是/clients/{client_id}/accounts/{account_id}/clients/{client_id}/accounts/,这个技巧很有用。控制器源码是:

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;
    }
}

欢迎关注Laravel-China

RightCapital招聘Laravel DevOps

    原文作者:SQL
    原文地址: https://segmentfault.com/a/1190000007088267
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞