Reputation: 61
I'm building a REST application and I have a doubt about the best practice in case of different routes calling the same controller method.
Example:
Route::post('/company/{id}/people/store', 'PeopleController@store')
Route::post('/people', 'PeopleController@store')
In the first case, I have an extra parameter $company_id to link the person to the company. Is it correct, or I should use a different method for each route?
Upvotes: 1
Views: 48
Reputation: 163748
Usually, you're storing form data, so just add an extra parameter using hidden input:
<input type="hidden" name="company_id" value="{{ $company->id }}">
Then in the store()
method you can get this parameter with:
public function store(Request $request)
{
$companyId = $request->company_id;
Upvotes: 0