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

Dalmar69's avatar

Eloquent relationship works on my Wamp environment but not on cpanel.

Symfony\Component\Debug\Exception\FatalThrowableError …/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php653

The relationship is a game and its location. It displays a list of the games at that location. It then eager loads the location name on the table along with game info.

My other tables that don't include eloquent relationships work just fine.

Again this works just fine in my wamp but not in my shared hosting Cpanel environment.

0 likes
6 replies
bobbybouwmann's avatar

So what is not working exactly? I see some error message, but in Laravel 5.5 that line in that file does not exist..

Are you sure you uploaded everything to your server?

Can you give some more information? What Laravel version do you use? How are your relations setup?

1 like
Dalmar69's avatar

https://sitewalkstudios.com/admin/games

Model for game

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Game extends Model 
{
    //
    public $timestamps = false;
    protected $guarded = ['id'];

    public function location(){
        return $this->belongsTo('App\Models\location');
    }

    public function scores(){
        return $this->belongsToMany('App\Models\User')->withPivot(['id','score','placed','check_in']);
    }
} 

Model for location

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Location extends Model
{
    //
    public $timestamps = false;
    protected $guarded = ['id'];

    public function games(){
        return $this->hasMany('App\Models\Game');
    }
}

Index for games

@foreach($games as $game)
                    <tr>
                        <td>{{ $game->location->locationName }}</td> <td>{{ $game->gameName }}</td> <td>{{ $game->date }}</td> 
                        <td><a class="btn btn-primary" href='/admin/games/{{$game->id}}/scores'>Scores</a></td>
                        <td><a class="btn btn-primary" href='/admin/games/{{$game->id}}'>Edit</a></td> 
                        <td>
                            <form action="/admin/games/{{$game->id}}" method="post">
                            {{ method_field('DELETE') }}
                            {{ csrf_field() }}
                            <button class="btn btn-danger" href="{{url('delete'.$game->id)}}" type="submit" name="delete">Delete</button>
                            </form>
                        </td> 
                    </tr>
                @endforeach 

Controller for the index

 public function index()
    {
        //
        $games = Game::all();
        return view('admin/games/index', compact('games'));
    }
Dalmar69's avatar

Cpanel:

Laravel version: 5.5.32

PHP version: 7.1.13

Local:

Laravel version: same.

PHP version: 7.1.12

I installed Laravel/composer on Cpanel through Softaculous Installer. Which gave me a blank laravel application then I copied over/overrode the files that needed to be added/updated.

RonB1985's avatar
RonB1985
Best Answer
Level 18

Change this:

public function location(){
        return $this->belongsTo('App\Models\location');
    }

To this:

public function location(){
        return $this->belongsTo(Location::class);
    }

Both files are in the App\Models directory, so not needed to declare the full namespace. Also, you declared location instead of Location, that's why you're getting that App\Models\location not found error..

You can also just change the location to Location:

public function location(){
        return $this->belongsTo('App\Models\Location');
    }
1 like
Dalmar69's avatar

.....OMG, it was because I was using 'l' in location and now 'L'.... omg... Thank you guys so much... I spent my whole day so very lost..... Thank you soo much.

How do I mark this discussion as solved?

1 like
RonB1985's avatar

I think on the left side by the reply that helped you there is an icon you can click. And no problem, glad we could help ofcourse.

1 like

Please or to participate in this conversation.