0

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 :)

3
  • You mean $request->input('nameValue'). But all methods are fine. Commented Nov 16, 2021 at 19:52
  • if you know you want a request "input" I would use input, if you use the dynamic property you could get an input or a route parameter Commented Nov 16, 2021 at 20:25
  • So 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 Commented Nov 16, 2021 at 20:29

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

So there is no difference between $request->value and $request->('value')
No difference between those two input requests. you can use laravel debug bar for check the progress and performance https://github.com/barryvdh/laravel-debugbar
make sure to ticket the answer
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.