Date format working in store but in edit there is error Hi,
The below code working in storing the data but it is not working when I edit the data
$date = Carbon::createFromFormat('d-m-Y', $request->th_bill_dt);
$account->th_bill_dt = $date;
It is saying the below error
Unexpected data found.
Unexpected data found.
Any one can you please help me?
Thank you
@bhhussain in your Account model you can add this:
protected $dates = ['th_bill_dt'];
which will automatically make your date field a carbon instance.
@nakov Thank you very much for your reply.
I added the code but still error is there
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class account extends Model
{
protected $dates = ['th_bill_dt'];
public function getRouteKeyName()
{
return 'th_tran_no';
}
public function item()
{
return $this->hasmany('App\item');
}
}
@bhhussain can you please show me the code where you get this error from?
What type is your field in the database as well? Is it just a date field or a datetime?
Edit View Page
<div class="form-group">
<div class = "row">
<label class = "col-lg-1" for="">Bill Date *</label>
<div class = "col-lg-2">
<input class = "form-control" id="datepicker" name = "th_bill_dt" value="{{ date('d-m-Y', strtotime($account->th_bill_dt)) }}" placeholder="Enter bill date" required>
<script>
$('#datepicker').datepicker({
uiLibrary: 'bootstrap4'
});
</script></div>
Only date field
Error
InvalidArgumentException
Unexpected data found.
Unexpected data found.
@bhhussain so the error is here most probably:
{{ date('d-m-Y', strtotime($account->th_bill_dt)) }}
Try this instead:
{{ $account->th_bill_dt->format('d-m-Y') }}
Since the th_bill_dt is already a Carbon instance when you have the $dates property in the model
@nakov Thank you very much.. It is working fine.
Please sign in or create an account to participate in this conversation.