简体   繁体   中英

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?

so far only Applicant route works, but if switch the order the other one shows 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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