ErrorException in HasRelationships.php
I need this error, but I'm not sure if it has to do with a relationship or something else?
Mistake
ErrorException in HasRelationships.php line 487:
Class 'Company' not found
User.php
public function company(){
$this->belongsTo('Company', 'user_id');
}
Company.php
public function user(){
$this->belongsTo('User') ;
}
Now my goal is to hide the "Create List" button in the navigation bar if the user is not related to the companies table. I know I can do this with roles or middleware, but a friend of mine sent me something like this and told me it was easier to do.
if(count($user->company) > 0)
So now I'm trying to figure out how, but still can't figure out how to fix the error.
Navigation type
@inject('user', 'App\User')
@if(count($user->company) > 0)
<li><a href="{{route('listings.create', [$area])}}">Add listing</a></li>
@endif
/// UPDATE
It didn't find the 'Company' class because I didn't use full namespaces in my relationship, but now I am getting this new error.
Mistake
ErrorException in HasAttributes.php line 403:
Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation
(View: /Users/username/Desktop/laravel/resources/views/layouts/partials/_navigation.blade.php)
(View: /Users/username/Desktop/laravel/resources/views/layouts/partials/_navigation.blade.php)
(View: /Users/username/Desktop/laravel/resources/views/layouts/partials/_navigation.blade.php)
source to share