Skip to content
Advertisement

Error while adding Eloquent class to User in Laravel

I want to make an eloquent model out of two table, pekerjaan and user. User hasMany pekerjaan and pekerjaan belongsTo User. How do I add eloquent’s method to the User class in Laravel? I have an error that shows:

Cannot declare class AppModelsUser, because the name is already in use

Here is my User.php model code:

JavaScript

And here is my Pekerjaan.php model:

JavaScript

Thank you

Advertisement

Answer

The error message says it what is the problem:

JavaScript

Your problem is you have 2 classes of User in your User.php. Remove the first User class put the function pekerjaans to the 2nd User class

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement