Im new to Laravel, and thought i would start out by creating a simple form. By searching around the internet, i've stumbled upon two ways of doing this, and i want to know which way is the right way or "best practice" way of doing things around here.
First of all i have a simple form
<form method="POST" action="/admin/product/save" class="form-horizontal" enctype="multipart/form-data" role="form">....</form>
Then i have a route that calls a method in my product controller
Route::post('/admin/product/save', 'ProductController@add');
And then comes my question. The method i have called "add" can handle the input in two ways. One being this way requring me to declare the "use Input" in top of the controller file:
use Input;
...
public function add()
{
return Input::all();
...
}
And then there is this way
public function add(Request $request)
{
return $request;
}
But what of these methods are considered the most correct way?
i dont think it matters as long as you are consistent and know what is happening..
I switched to the second version because I like to use FormRequests as Validation. Since I typehint the FormRequest anyway I have access to all the parameters through the $request object too.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community