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

salkfdhjkh's avatar

Request validation fails after Validator file name change

I had form validation for some page content editing working.

I then decided that I need another category of page and content types so I changed the Content Model name and table names from Content and contents to InfoContent and info_contents respectively.

Up to this point, everything was still working.

I then changed the name of the working request validator from UpdateContentRequest.php to UpdateInfoContentRequest.php. and then changed it accordingly in the Class usage and InfoContentController update method eg;

use App\Http\Requests\UpdateInfoContentRequest;
public function update(UpdateInfoContentRequest $request, $id)

Now when I try to save any InfoContent changes to the database, I get the following error;

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'app_database.contents' doesn't exist

So rather than using the table defined by the model, app_database.info_contents, the validator is looking for the original table name, ie; app_database.contents.

If I disable the call to the validator in the controller update method, ie;

public function update(Request $request, $id)

then it works again albeit without validation.

I thought perhaps that the validator might be registered somehow when it is created via the Artisan command so I tried creating a new one with the proper name , ie; UpdateInfoContentRequest.php but it still causes the validation to look for the old table name.

So I seem to be missing something, any ideas?

0 likes
3 replies
Snapey's avatar
Snapey
Best Answer
Level 122

Do you have something that checks the database in the formRequest class such as a unique rule or exists rule?

Can you show the formRequest class?

salkfdhjkh's avatar

@Snapey , yes I do and this just goes to show how a new day can refresh the eyes. Your comment took me directly to the problem, many thanks.

Old rule;

'file_name' => 'unique:contents,image,'.$this->id,

New rule;

'file_name' => 'unique:info_contents,image,'.$this->id,

Cheers.

Snapey's avatar

Yep, it goes like that. The validation rules go straight to the table rather than the model.

Please or to participate in this conversation.