Is there a way to set Laravel Collective date picker format to yyyy-mm-dd?
I am using now:
{{ Form::date('deadline', null,['class' => 'form-control']) }}
but in the front end I get an input field with mm/dd/yyyy inside. I tried parsing the Carbon instance as second parameter, but that does nothing.
{{ Form::date('deadline', \Carbon\Carbon::now()->format('Y-m-d'),['class' => 'form-control']) }}
You could pass an DateTime instance for the second parameter. As per the source code if the second parameter is an DateTime instance it would return the formatted date (Y-m-d).
So you could try this,
{{ Form::date('deadline', new \DateTime(), ['class' => 'form-control']) }}
Note:
As #Ajahi himalil stated in the comment, the value in the request would be different from the one selected. Please verify the data on form submission.
No, Laravel Collective does not provide this option.
Use https://eonasdan.github.io/bootstrap-datetimepicker/
{{ Form::text('deadline', null, ['class' => 'form-control', 'id'=>'datetimepicker']) }}
Javascript
$('#datetimepicker').datetimepicker({
format: 'yyyy-mm-dd'
});
After applying all these methods and nothing working. simple input tag with date type is the only solution that i came to know instead of collective laravel.
Related
I have laravel and have this function to print the date when the user registered on our site
{{ __("Member Since :time",["time"=> date("M Y",strtotime($user->created_at))]) }}
But it gives "Oct" (English). But i want this in German. But how can i make this in frontend?
Thats the code in the frontend file
<p class="profile-since">{{ __("Member Since :time",["time"=> date("M Y",strtotime($user->created_at))]) }}</p>
You should use setlocale()
https://www.php.net/setlocale
setlocale(LC_ALL, 'de_DE#euro', 'de_DE', 'de', 'ge');
If you set this before you echo your code it should change to the locale
Or if you use carbon you can change it globally in config/app.php
'locale' => 'id'
I have created a blade (using Laravel Collective) with a multipe checkboxes:
#foreach($subsc as $subsc)
<div>
{{Form::checkbox('checkbox['. $subsc->Scheme->Scheme_id .']', '1')}}
{!! Form::label('SchemeName', $subsc->Scheme->Scheme_Name.$subsc->Scheme->Scheme_id, ['class' => 'control-label']) !!}
</div>
#endforeach
Now I want to save each checked box in a table as the scheme_id. How do I do that?
I guess you could use an array as name to make it easier and try something like this.
Form::checkbox('schemeIDS[]', $subsc->Scheme->Scheme_id, true);
// Parameters checkbox: name, value, checked
In the controller function use
$schemeIDS = $request->get('schemeIDS'); // get all the checked values as array
foreach($schemeIDS as $schemeID)
{
// insert into the database
}
Im making a edit form for my app and i was wondering if someone could tell me how to get the data from the database into my text field.
I can locate the record i need to edit based on the users click, and i can display the information if i do the following:
value="{{ $letter->subject }}"
BUT, the problem im having is that when i run it through the validation and there is an error, it comes back with the database information instead of the OLD data.
So my questions is. Is there a way to serve up the database information first and then when it goes through the validatior, validate the information the user has edited?
Currently to validate the text field and bring the data back incase of error, im using
Input::old('subject')
Is there a parameter for that old bit that allows me to put in the DB data?
Cheers,
Hey you could validate and return ->withInput() and then in your actual form, check if there is Input::old() and display it, otherwise display from the db.
example:
<input type="text" name="subject"
value="{{ (Input::old('subject')) ? Input::old('subject') : $letter->subject }}">
Or you could go the other way and define the variable and do a regular if statement, instead of the ternary one! Up to you to decide what you want to use!
All you need is form model binding http://laravel.com/docs/html#form-model-binding:
{{ Form::model($letter, ['route' => ['letters.update', $letter->id], 'method' => 'put']) }}
// your fields like:
{{ Form::text('someName', null, ['class' => 'someHTMLclass' ...]) }}
// no default values like Input::old or $letter->something!
{{ Form::close() }}
This way you form will be populated by the $letter data (passed from the controller for example).
Now, if you have on your countroller:
// in case of invalid data
return Redirect::back()->withInput();
then on the redirect your form will be repopulated with input values first, not the original model data.
Make it more simple and clean
<input type="text" name="subject" value="{{ (Input::old('subject')) ?: $letter->subject }}">
I'm not sure for Laravel 4 but in Laravel 5, function old takes second param, default value if no old data in session.
Please check this answer Best practice to show old value
Using Laravel 4's Form class, we can create a list using
{{ #Form::select('colors', Colors::all()), $color }}
Question: How can we add the attribute disabled using Blade without having to rewrite the clean Blade syntax into the usual ugly form?
Just add array('disabled') in the end like:
{{ Form::select('colors', Colors::all(), $color, array('disabled')) }}
This should do the work.
{{ #Form::select('colors', Colors::all()), array(
'disabled' => 'disabled',
'class' => 'myclass'
) }}
Though already answered, IMO both answers weren't neutral enough, so to avoid duplicates the arguments are
#Form::select('name', $optionsArray, $selectedOption, ['disabled']).
So if you're prepopulating form with #Form::model() you should do #Form::select('name', $optionsArray, null, ['disabled']) - array with 'disabled' has to be 4th parameter.
{{ Form::text('username', Input::old('username')) }}
This is my code, I want to add Username as placeholder in the text box. I already use bootstrap in the project.
I tried to use the example
{{ Form::text('username', 'Username', Input::old('username')) }}
But it gives a default value which needs to be deleted and then the user has to type his value. I want something like how it shows up on Twitter.com etc. Which gets erased once user types into it.
{{ Form::text('username', Input::old('username'), array('placeholder'=>'Username')) }}
This works for Laravel 4!!
{{ Form::text('username', null, array('placeholder'=>'Username' )); }}
Use:
{{ Form::text('txtUsername', '',array('class'=>'input', 'placeholder'=>'Username')) }}
Been a while since this was updated but with Former for Laravel the way to do this would be:
Former::text('field')->placeholder('langfile.path.to.placeholder.text')))
The lang file would be called langfile.php with the array containing:
<?php
return array (
'path.to.placeholder.text' => 'Some Placeholder Text.'
);
In case somebody wonders how this should work for a password field:
{{ Form::password('password', array('placeholder'=>'Password')) }}