1

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


lx1036
3.1k 声望923 粉丝

为五斗米折腰