Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert a value to hidden input Laravel Blade

Tags:

How to pass a value to hidden input ?

Create form :

@if (isset($id))     {!! Form::hidden('edition', $id) !!} @endif 

I got the form id by url like this :

<a href="../journal/create?edition={{$edition->id}}" class="btn btn-primary">Add Journal</a> 

( when I click Add Journal button it will shows a create form with edition id at the url)

and the controller is :

$id = $request->get('edition');         $journal = Edition::findOrFail($id)->journal()->create($input); 

The result gave me this error "No query results for model [App\Edition]."

like image 682
Ariando Miller Avatar asked Sep 04 '16 08:09

Ariando Miller


People also ask

How to send hidden value from blade to laravel controller?

In your form, you need to mention the hidden field type, name and value with a input tag. Since this is a post request, the data value would be sent to the controller in your "any-name" variable. Route::post('your-url', 'NameController@yourFunction');

How to make a form as hidden in laravel?

Use the Form::hidden() method. Usually, this is used in Blade templates. Just pass the name and value to the method.

How do you pass an input hidden array?

If you want to post an array you must use another notation: foreach ($postvalue as $value){ <input type="hidden" name="result[]" value="$value."> }


2 Answers

Usually, this is used in Blade templates.

Just pass the name and value to the method.

{{ Form::hidden('invisible', 'secret') }} 

This creates a very simple element which looks like the following.

<input name="invisible" type="hidden" value="secret"> 

To add other attributes, pass a third argument to the method. This third argument must be an array.

{{ Form::hidden('invisible', 'secret', array('id' => 'invisible_id')) }} 

Now the input has an id attribute.

<input id="invisible_id" name="invisible" type="hidden" value="secret"> 

Check out : Creating a Hidden Input Field


If still not work check you project have Laravel Collective installed

In controller method check

public function store(Request $request) {     $name = $request->input('name'); } 
like image 184
Jarvis Avatar answered Sep 20 '22 15:09

Jarvis


you can do this with the help of blade <input type="hidden" value="{{$user->id}}" name="user_id">

like image 23
danoj.I Avatar answered Sep 21 '22 15:09

danoj.I