quick question, about User Input Request to Laravel:
public function store(Request $request)
{
$name = $request->nameValue; //Doc: $name = $request->('nameValue');
}
Do I have to put all Requests as mentioned in Doc or is the "quick" way also allowed?
There is no difference between $request->value and $request->('value')? Both are working fine so far - but I do not want have any security issues if Im working with $request->value only.
Thanks alot for your help :)
CodePudding user response:
I do not think that there will be too many performance issues for different methods to access request's inputs ... anyway, I will cut an old answer for this question from this answer.
use Illuminate\Http\Request;
get() and input() are methods of different classes. First one is method of Symfony HttpFoundation Request, input() is a method of the Laravel Request class that is extending Symfony Request class.
so, I think the better one is input()
method.
CodePudding user response:
on laravel, there is a specific class named Illuminate\Http\Request
which provided an object-oriented way to interact with HTTP request which are send by client-side
- ACCESSING THE REQUEST (both are same speed on accessing data)
$name = $request->input('name');
$name = $request->name;
- Dependency Injection & Route Parameters
use App\Http\Controllers\UserController; // call the controller
Route::put('/user/{id}', [UserController::class, 'update']); // set a slug as a parameter on routes
public function update(Request $request, $id)
{
return $id; // access the parameter by contoller
}
- Retrieving The Request Path
$uri = $request->path(); // will fetch the path
- Retrieving The Request Method
$method = $request->method(); // will fetch the method of request EG: GET / POST / PUT / DESTROY
for more information check it on official documentation LARAVEL