Im gettings this error, but i'm not sure is it because of the relationship or something else?
Error
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 "Create Listing" button in navigation bar, if user doesn't have relation with companies table. I know i can make it with roles or middleware, but my friend send me something like that and told me its easier to make that way.
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 view
@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 class 'Company', because i wasn't using full namespaces in my relationships, but now i'm getting this new error.
Error
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)
Use full namespace in the relationship code:
public function company()
{
return $this->belongsTo('App\Company', 'user_id');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With