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

bmcconn's avatar

Help with FatalErrorException - Class 'App/User' not found

I have a model called Round (below) that has a one to many relationship with the model User.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Round extends Model
{
    /**
     * A round is played by a user.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user() {
        return $this->belongsTo('App/User');
    }

In my RoundsController, I have a show() function attempting to return the user of a particular round.

<?php

namespace App\Http\Controllers;

use App\Round;
use Illuminate\Http\Request;

use App\Http\Requests;

class RoundsController extends Controller
{
    public function show($id)
    {
        return Round::find($id)->user();
    }

When i attempt to do this I get a FatalErrorException - class 'App/User' not found in Model.php

I know this is usually a namespace issue, but all my models are in the 'App' namespace. When I try something like Round::find($id), it works just find. It only seems to break down when I try and use relationships. I've googled around and am struggling to find an answer.

Thanks for the help.

0 likes
3 replies
tomopongrac's avatar
Level 51

Try this

namespace App;

use Illuminate\Database\Eloquent\Model;

class Round extends Model
{
    /**
     * A round is played by a user.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */

public function user() {
    return $this->belongsTo('App\User'); // --- this line is changed
}
bmcconn's avatar

Oh jeez, I was afraid it was going to be something like that. Thanks a lot.

Snapey's avatar

Personally, I prefer

namespace App;

use Illuminate\Database\Eloquent\Model;

class Round extends Model
{
    /**
     * A round is played by a user.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */

public function user() {
    return $this->belongsTo(App\User::class); //this line is changed
}

Please or to participate in this conversation.