Laravel change input value
You can use Input::merge()
to replace single items.
Input::merge(['inputname' => 'new value']);
Or use Input::replace()
to replace the entire input array.
Input::replace(['inputname' => 'new value']);
Here's a link to the documentation
How to change value of a request parameter in laravel
Use merge()
:
$request->merge([
'user_id' => $modified_user_id_here,
]);
Simple! No need to transfer the entire $request->all()
to another variable.
Read more about Laravel's merge()
here:
https://laravel.com/docs/collections#method-merge
Better way to conditionally set input value in laravel-blade
You can pass a second argument to old
, it will use as default value, so you can have your code like:
<input type="text" id="name" name="name" class="form-control" value="{{ old('name', isset($category) ? $category->name : '') }}">
Still a little ugly, but way better than having that if.
How update the value of input and send into Request Laravel?
Your inputs have disabled attribute which means they are not send after form submition just remove that and you should be able to see your inputs on backend
How To change input type value in Laravel with if statement
You have to use jquery :
$(document).ready(function(){ $('#company').val('Com 1'); $('#company').trigger('change');});
$(document).on('change','#company',function(){ if($(this).val()=='Com 1'){ $('#address').val("Address of Company 1"); }else if($(this).val()=='Com 2'){ $('#address').val("Address of Company 2"); } else{ $('#address').val("Default Address"); }});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Address : <input type="text" class="form-control" name="add" value="" id="address">
Company Name :<select id="company" name="company"> <option value="Com 1">Com 1</option> <option value="Com 2">Com 2</option></select>
Changing values of laravel inputs
After calling \Input::merge()
have you tried calling \Input::get()
doesn't it give you the merged array?
Because \Input::merge()
only adds the new set of input parameters that you pass and not return anything.
Let me know if this works:
public function myMethod(){
Input::merge(array('myInputName' => 'theValueFromDatabase'));
$newInputVariables = \Input::get('myInputName');
$allVariablesWithNewInput = \Input::all();
}
Laravel blade set value on input with ternary if
I think a ternary operator it is not needed in this case, since you will do nothing in case condition result false
.
You can use just @if
:
@if (isset($category)) value="{{$category->name}}" @endif
Also, there is an @isset
directive, so could be more appropriate if you do:
@isset($category) value="{{$category->name}}" @endisset
In your input
<input type="text" class="form-control" name="name" id="name" @isset($category) value="{{$category->name}}" @endisset />
Ref: Blade Directives If Statements.
Depending on Select option change others value on div and input field in Laravel
I have figured out a solution for this.
Here is my code:
<select name="offer_id" id="parent_id" class="form-control dynamic" data-dependent="details">
<option value=""> Select Offer</option>
@foreach ( $offers as $row )
<option value="{{ $row->id }}">{{ $row->name }}</option>
@endforeach
</select>
@foreach($offers as $row)
<div class="some" id="some_{{ $row->id }}" style="display:none;">
{{ $row->details }}
</div>
@endforeach
<script type="text/javascript">
$('#parent_id').on('change',function(){
$(".some").hide();
var some = $(this).find('option:selected').val();
$("#some_" + some).show();}); </script>
Related Topics
How to Select Rows Where Column Value Is Not Null Using Codeigniter's Activerecord
PHP Remove Elements from Associative Array
PHP How to Create Multiple Sessions
"Class Xxx Is Not a Valid Entity or Mapped Super Class" After Moving the Class in the Filesystem
Create Table with PHP and Populate from MySQL
How to Add Query Parameters in the Zf2/Zf3 Url View Helper
Secure and Flexible Cross-Domain Sessions
PHP Datetime Microseconds Always Returns 0
Php: Catch Exception and Continue Execution, Is It Possible
Best Way to Internationalize Simple PHP Website
Warning: "Continue" Targeting Switch Is Equivalent to "Break". Did You Mean to Use "Continue 2"
Where Do I Put a Database Query in MVC