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

jrmypttrsn's avatar

protected $fillable/protected $date not updating

I have a weird one happening. I have two fields, one of which ('response') is getting updated, the other ('resp_received') is not. I've tried both of the following in my controller and get the same result -- 'response' gets set but 'resp_received' does not.

Option 1:

// Response received datestamp
if ($request->update_type === 'response_received_datestamp') {
    $notice->resp_received = $request->resp_received;
    $notice->response = $request->response;

    return back()->with('success', 'Response updated!');
}

Option 2:

// Response received datestamp
if ($request->update_type === 'response_received_datestamp') {
    $notice->update([
        'resp_received' => $request->resp_received,
        'response' => $request->response
    ]);

    return back()->with('success', 'Response updated!');
}

In my model:

protected $fillable = [
    ...,
    'response',
    'resp_received',
    ...
    ];
protected $dates = [
    ...
    'resp_received',
    ...
    ];

And the form from my blade file:

<div class="modal fade row" id="response_received_datestamp_{{ $notice->id }}" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Set Response Received</h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <form method="POST" action="{{ route('notices.update', $notice) }}">
                @csrf
                @method('PATCH')
                <div class="modal-body">
                    <input type="hidden" value="response_received_datestamp" name="update_type">
                    <div class="form-group">
                        <label for="resp_received">Response Received</label>
                        <input type="date" id="resp_received" name="resp_received" class="form-control" value="{{ \Carbon\Carbon::now()->format('Y-m-d') }}">
                    </div>
                    <label for="response">Enter Response</label>
                    <textarea class="form-control" id="response" name="response"></textarea>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-success">Set Response Received</button>
                </div>
            </form>
        </div>
    </div>
</div>

Any thoughts would be greatly appreciated.

0 likes
6 replies
bugsysha's avatar

I've never tried setting date-time property to string. Maybe that is the reason why it is causing issues.

Try

$notice->resp_received = Carbon::createFromFormat('Y-m-d', $request->resp_received);
siangboon's avatar

i guess may be the format issue.

try hard code it first to confirm the update have no issue

$notice->resp_received = now();

try return $request->resp_received before the update to check the format according to the column

Snapey's avatar

in your option 1, you never save the model?

If you are saving and not showing that line for some reason, then $fillable is irrelevant because you are not doing mass assignment.

Option 2 uses mass assignment, but I doubt this is your issue.

jrmypttrsn's avatar
jrmypttrsn
OP
Best Answer
Level 4

I wish I could blame it on something other than poor sleep but it is what it is.

I had mistakenly placed an if further up in the code that handles editing just the 'response' request. With it now in the proper position option 2 is working as it should.

@snapey, yes my mistake for not showing the save() and including the redirect. That's what tipped me off. @bugsysha and @siangboon, I did try your suggestions before realizing my stupidity. Thanks for that.

bugsysha's avatar

Since you've said that in both options one property was saved there was no doubt that you were calling save() on a model, but just hiding it for some reason. I know that situations should be simplified when asking for help, but that is not always good thing to do.

Please or to participate in this conversation.