Reputation: 2686
This is my form:
<form class="form-horizontal" method="POST" action="{{ url('/categories/new') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input class="btn btn-default" value="Cancel" type="reset">
</form>
This is my url where my form is located: /categories/new
This is my route:
Route::get('/categories/new', 'Admin\CategoriesController@newCategory');
I want to keep the new
method, so i want to check if there is a post method do smth else load the view with my form. How can I achieve this in laravel 5. I'm a newbie so all of the detailed explanations are welcomed. Thank you !
Upvotes: 1
Views: 46
Reputation: 163768
If you want to use single method for both POST
and GET
requests, you can use match
or any
, for example:
Route::match(['get', 'post'], '/', 'someController@someMethod');
To detect what request is used:
$method = $request->method();
if ($request->isMethod('post')) {
https://laravel.com/docs/master/requests#request-path-and-method
Upvotes: 3
Reputation: 2076
Add this to your rotes file:
Route::post('/categories/new', 'Admin\CategoriesController@someOtherFunctionHere');
Upvotes: 0