Skip to main content

Manage Transactions with Eloquent Mutators

Premium
5:35

The Full Lesson is Only for Premium Members

Want to access all of our courses? (36 h 00 min)

You also get:

61 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Richard A. Hoyle avatar

Sorry about this but I am getting a error again. "message": "The transaction date field must be a valid date.", "errors": { "transaction_date": [ "The transaction date field must be a valid date." ] } status: 422 Unprocessable Content transaction_date 02-23-2023

use Carbon\Carbon;
 
class Transaction extends Model
 
public function setTransactionDateAttribute($value)
{
$this->attributes['transaction_date'] = Carbon::createFromFormat('m/d/Y', $value)
->format('Y-m-d');
}
 
If I comment this out it work but the date does not change
 
The update methad will not work either get the same error message.
marko_mo avatar

Fix for Laravel 10

public function setTransactionDateAttribute($value)
{
$this->attributes['transaction_date'] = \Carbon\Carbon::parse($value)->format('Y-m-d');
}
Velkacem avatar

please give us the source code of this course or the github link