date - Where to put this code in laravel? -
i have table in database has 3 columns of type date, stored in y-m-d format. need dates displayed in views d/m/y. model table jobcard.php, every time retrieve instance of jobcard this:
$jobcard -> datereqlatest = carbon::createfromformat('y-m-d', $jobcard -> datereqlatest)->format('d/m/y'); $jobcard -> dateissued = carbon::createfromformat('y-m-d', $jobcard -> dateissued)->format('d/m/y'); $jobcard -> datedespatch = carbon::createfromformat('y-m-d', $jobcard -> datedespatch)->format('d/m/y');
i pass $jobcard view. works there several views making use of model , these views use different controllers rather copying code every controller function, want date format automatically converted when pass instance of jobcard view.
the user submit dates in form in d/m/y format need covert y-m-d stored in database.
where best write code this?
you can create acessor called every time access property:
public function getdatereqlatestattribute($value) { return carbon::createfromformat('y-m-d', $value)->format('d/m/y'); }
Comments
Post a Comment