Reputation: 213
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 :)
Upvotes: 0
Views: 592
Reputation: 953
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
$name = $request->input('name');
$name = $request->name;
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
}
$uri = $request->path(); // will fetch the path
$method = $request->method(); // will fetch the method of request EG: GET / POST / PUT / DESTROY
for more information check it on official documentation LARAVEL
Upvotes: 1
Reputation: 12188
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.
Upvotes: 0