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

jim1506's avatar

Using sub directories for models (5.3)

I have to use 3 databases for a project with regretably similar names for tables. I thought I would place them in sub directories so I created one under App called xmaster and place my models in there. To try my idea I have one - Section.

I thought then I should be able to reference it simply by amending the path in my web.php file:

Route::get('XProducts/Builder', function(){ $section = new App\xmaster\Section(); $sections = $section->with('sectionType'); return view('xmaster.builder.sections',['sections'=>$sections]); })->name('builderfront');

but I get an

Class 'App\xmaster\Section' not found

error, even if I add

uses App\xmaster\Section

Some help would be gratefully appreciated!

0 likes
3 replies
BrandonSurowiec's avatar
Level 14

Does your app\xmaster\Section.php file have namespace App\xmaster; declared at the top?

1 like
Snapey's avatar

Your models don't have to share the table names you could differentiate the models by prefix or suffix and then add a $table variable in the model to tell eloquent what the real table name is.

If you move your model to App\xmaster then you need to change the namespace at the top of the model

1 like
jim1506's avatar

It does now and it works. Cheers Niban!

Please or to participate in this conversation.