Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KIDJourney's avatar

Form Model Accessors doesn't work

When I am trying to use form model binding to refill the edit form , everything works fine except the date input .

After defining a Accessor thing goes OK but i don't want the date format applied to all of my application .

After searching I found Form Model Accessors , But it seems not working for me .

Here is my form .

{!! Form::model($activity , ['method' =>'PATCH' , 'action'=>['Manage\ActivityController@update' , 'club'=>$club , 'activity'=>$activity->id]]) !!}
<div class="form-group">
    {!! Form::label('start_at') !!}
    {!! Form::input('date' , 'start_at' , null , ['class'=>'form-control']) !!}
</div>
<div class="form-group">
    {!! Form::label('expired_at') !!}
    {!! Form::input('date' , 'expired_at' , null , ['class'=>'form-control']) !!}
</div>
<div class="form-group">
    {!! Form::submit("submit", ['class' => 'btn btn-primary from-control']) !!}
</div>
{!! Form::close() !!}

Here is my Form Model Accessors .

public function formStartAtAttribute($date)
{
    return Carbon::parse($date)->format('Y-m-d');
}

public function formExpiredAtAttribute($date)
{
    return Carbon::parse($date)->format('Y-m-d');
}

How can I make the date display correctly ?

0 likes
3 replies
thomaskim's avatar
Level 41

Interesting. Based on the code, it looks like you need to pull in the trait. I'm not sure why this is not documented, but try adding this to your model:

use Collective\Html\Eloquent\FormAccessible;

class Model extends... {

    use FormAccessible;

}
5 likes
N9ne's avatar

@thomaskim I have been pulling my hair out about this for a while. Thank you for posting this - it has solved a big problem for me and I'm sure countless others. Definitely a need for better documentation on this (amongst many things).

3 likes

Please or to participate in this conversation.