简体   繁体   English

问:有没有办法在 Laravel 中的单个 controller 上使用两种不同方法的两条 GET 路由?

[英]Q: Is there any way to use two GET routes with two different methods on a single controller in Laravel?

Instead of using two profile controllers for two user types, is it possible to use one controller with two different methods to show profiles of each user types?除了对两种用户类型使用两个配置文件控制器之外,是否可以使用一个 controller 和两种不同的方法来显示每种用户类型的配置文件?

so far only Applicant route works, but if switch the order the other one shows 404 | Not Found到目前为止只有申请人路线有效,但如果切换顺序另一条显示404 | Not Found 404 | Not Found . 404 | Not Found

Route::get('/accounts/{applicant}', 'ProfileController@applicant');
Route::get('/accounts/{employer}', 'ProfileController@employer');

class ProfileController extends Controller
{
    public function applicant(Applicant $applicant)
    {
        return view('applicant.show', compact('applicant'));
    }

    public function employer(Employer $employer)
    {
        return view('employer.show', compact('employer'));
    }
}

You can't.你不能。 There is no difference in the request itself on both routes.两条路线上的请求本身没有区别。 Either you use another route, or make a method which can handle both applicant and employer , but you'll still need to figure out how to differentiate these two.您要么使用另一条路线,要么制作一种可以同时处理申请人雇主的方法,但您仍然需要弄清楚如何区分这两者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM