OK, I was called again, but pff...
@eliaseas Choose the approach that suits you, that's all. Below is something for you to consider, and btw yes, use $dates handling provided by the Eloquent and skip the accessor.
Mutator, on the other hand, is completely different thing here and it's just making your work easier - if you want Eloquent do the job for you, then use it, otherwise you will have to take care of it:
// very basic controller as a sensible example, using mutator
public function store()
{
// input validation
// ...
$user = User::create(Input::all());
return Redirect::route('users.show', [$user->id]);
}
// vs no mutator
public function store()
{
// input validation
// ...
$user = new User(Input::except('dob'));
$user->dob = Carbon::createFromFormat(
$u = Auth::user()
? $u->format
: 'd/m/Y', // here you asked fellow programmer about the default format, luckily he recalled ;)
// Now, really: controller is not the best place for placing business default values
// neither is a repository - that's what I think, make your own opinion
Input::get('dob')
)
$user->save();
return Redirect::route('users.show', [$user->id]);
}
The above obviously will work considering fillable / guarded attributes, but that's different story.
Now, there's also no problem with your requirement concerning different format. Let's stick to the previously mentioned per user setup:
public function setDobAttribute($value)
{
// I suppose Eloquent model is much better place for storing default format
// of course it might be retrieved from config, or wherever you like instead
$format = ($u = Auth::user()) ? $u->format : 'd/m/Y';
$this->attributes['dob'] = $this->fromDateTime(Carbon::createFromFormat($format, $value));
}
WIth this setup all you need in the example controller above is again:
public function store()
{
// input validation, check the dob format according to the user/location
// and don't worry about it no more, Eloquent will handle it for you
$user = User::create(Input::all());
return Redirect::route('users.show', [$user->id]);
}
That's what you can use mutator in your case.
Pretty much everything has been already said about outputting the date, so I'm not touching this topic again.