Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 getting input values that are arrays

I have a text field like

{!! Form::textarea('representive[address_1]' ,null ,['class' =>'textboxlong form-control','style'=>'height:60px;']) !!}

In my form. And when I try to get its value in my controller but it comes null. What I try is

$adress = Request::get('representive.0.address_1');

I also tried some other ways but could not end up with a proper solution. How can I get the value of this field? Any help would be appreciated.

like image 882
Tartar Avatar asked Jun 14 '15 16:06

Tartar


People also ask

How to validate array input in Laravel?

you can call validate() method directly on Request object like so: $data = $request->validate([ "name" => "required|array|min:3", "name. *" => "required|string|distinct|min:3", ]); Hope it helps!!

What is use Illuminate Http Request in Laravel?

Laravel's Illuminate\Http\Request class provides an object-oriented way to interact with the current HTTP request being handled by your application as well as retrieve the input, cookies, and files that were submitted with the request.

How do I get params in laravel?

Laravel routes are located in the app/Http/routes. For instance, to pass in a name parameter to a route, it would look like this. Route::get('/params/{name}', function ($name) { return $name }); By convention, the Controller function accepts parameters based on the parameters provided.

How to retrieve input values in Laravel?

The input values can be easily retrieved in Laravel. No matter what method was used “get” or “post”, the Laravel method will retrieve input values for both the methods the same way. There are two ways we can retrieve the input values. Using the input () method. Using the properties of Request instance.

How to validate array elements in a form in Laravel?

HTML doesn’t provide a limit on the number of array elements that you can submit in a form, so if we had to validate each individually, it would be a headache. Luckily, Laravel provides a simple way to validate arrays and nested array input with the use of dot notation and the * character.

How to validate if a phone number is valid in Laravel?

There’s equally validation for each value in the array, if the value is not null, it should be a valid phone number. P.S., my project uses the Laravel Collective package.

Is it possible to get value from input file as array?

The name of the input file is an array. It's work fine if I want to get value of the input file just the normal name. The value return is empty. What I want is to get value from input file as array.


1 Answers

The Request::get() method is implemented by Symfony\Component\HttpFoundation\Request which the Illuminate\Http\Request class extends. This method does not parse the string parameter passed using the dot notation as Laravel does. You should instead be using the Request::input which does:

$adress = Request::input('representive.address_1');

As an alternative you can also use the Input facade and do Input::get().

like image 57
Bogdan Avatar answered Oct 09 '22 22:10

Bogdan