I would be more concerned about writing the validated data directly into the model (I assume thats what you are doing)
I assume you need the created_at to be validated because you are mass assigning?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
hello again , i have a invoice table , there's timestamps inside , my idea is form to edit invoice data but when the user change the date just the date the created at will be updated with the date selected by the user and the current time - i know it's bad idea but the client needed :D - now i make a StoreRequest with the following code
<?php
namespace App\Http\Requests\Admin\Invoice;
use App\Helpers\Classess\CanAccess;
use Carbon\Carbon;
use Illuminate\Foundation\Http\FormRequest;
class StoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return CanAccess::permission('can_moderate_invoices');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
"name" => ['required', 'min:3', 'max:255'],
"description" => ['required', 'min:3', 'max:255'],
"recipient" => ['required', 'min:3', 'max:255'],
"amount" => ['required','numeric','digits_between:1,20'],
"type" => ['required','numeric','digits_between:1,2'],
'created_at' => ['required','date_format:Y-m-d H:i:s']
];
}
protected function prepareForValidation()
{
$this->merge([
'created_at' => date('Y-m-d H:i:s', strtotime($this->created_at.Carbon::now()->format('H:i:s')))
]);
}
}
it work very good but i think it not the best practice cause we have a code review and the team leader give me a warning for thad
Please or to participate in this conversation.