Ahmed AbdElNasser
Ahmed AbdElNasser

Reputation: 79

Laravel Models and Controller files naming

Hello I want to know if there is a special naming convention for laravel models and controllers files, I created a model post.php and when I tried to use this model I got a fatal error said the class post is not found but when I changed the file name to be Post.php instead of (post.php) it works fine and the exception is gone anyone could explain why this happened?
Thanks.

Upvotes: 3

Views: 1621

Answers (1)

apokryfos
apokryfos

Reputation: 40673

What you're describing sounds less like a naming convention issue and more of a PSR-4 compliance issue.

Specifically, point 2.6:

All class names MUST be referenced in a case-sensitive fashion.

So for example, since you named the file post.php then the file must contain a class post and be referenced as new post(). This will ensure the composer PSR-4 autoloader will pick it up.

If you, however, have a file called Post.php then it must contain a class Post and be referenced as new Post().

Upvotes: 9

Related Questions