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。