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

Classified's avatar

Laravel 5.7 Undefined index: App\Company

Hello,

I am really confused by this error that I am getting straight after updating my laravel application.

ErrorException (E_ERROR) Undefined index: App\Company (View: C:\xampp\htdocs\test\resources\views\partials\main_navigation.blade.php) (View: C:\xampp\htdocs\test\resources\views\partials\main_navigation.blade.php) (View: C:\xampp\htdocs\test\resources\views\partials\main_navigation.blade.php)

Anybody know why this error is occuring, I've followed the upgrade guide.

0 likes
5 replies
Classified's avatar

There are no observers connected to the User model, no.

User model

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

use Spatie\Permission\Traits\HasRoles;
use Illuminate\Database\Eloquent\SoftDeletes;

class User extends Authenticatable
{
    use Notifiable, HasRoles, SoftDeletes;

    protected $guard_name = 'web';
    
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'company_id', 'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function company() {
        return $this->belongsTo('App\Company', 'company_id');
    }
}

and the error occurs from this block

@if(request()->user()->company->logo_storage_path)
    <img src="{{ route('logo.company', ['company' => request()->user()->company]) }}"/>
@else
    <img src="{{ asset('images/logo.png') }}"/>
@endif
Tomi's avatar

And your Company model also not using any Boot functionality ?

Could you please post a more detailed error message?

The part above is only where the error starts.

You might want to remove all the traits you are using to be sure the error has nothing to do with one of your packages.

use Notifiable, HasRoles, SoftDeletes;

Classified's avatar

I completely forgot about the boot in my Company model, adding parent::boot(); to the top fixed it.

Cheers @Tomi

3 likes

Please or to participate in this conversation.