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

esorone's avatar

Solved: Undefined variable:

Hello All,

I ran into issues, which causes me a real headache. I guess I'm doing something really stupid, but I cannot find the error.

Its all about Undefined variable: Overview.

The only thing I would like to show is an overview of some results. My resultsController:

/**
     *Show overview per user
     */

        public function overview()
        {
        $results = Result::all()->load('user');
        $results = $results->where('user_id', '=', Auth::id());
            // dd($results);
        return view ('users.overview', compact('results'));

        }

Outcome of my DD:

Collection {#440 ▼
  #items: array:1 [▼
    0 => Result {#433 ▼
      #fillable: array:4 [▼
        0 => "correct"
        1 => "date"
       ** 2 => "user_id" **
        3 => "question_id"
      ]
      #connection: null
      #table: null
      #primaryKey: "id"
      #keyType: "int"
      #perPage: 15
      +incrementing: true
      +timestamps: true
      #attributes: array:8 [▶]
      #original: array:8 [▶]
      #relations: array:1 [▶]
      #hidden: []
      #visible: []
      #appends: []
      #guarded: array:1 [▶]
      #dates: []
      #dateFormat: null
      #casts: []
      #touches: []
      #observables: []
      #with: []
      +exists: true
      +wasRecentlyCreated: false
      #forceDeleting: false

And My overview.blade.php:

@section('content')
    <div class="main-container">
        <div class="row background">
            <div class="col-xs-12 marge-top">
            <h1>Account Overview</h1>
                {{ $overview->user_id }}
            </div>
        </div>
    </div>  

Unfortunately I receive the mentioned error. I hope someone can help me out

0 likes
3 replies
36864's avatar
36864
Best Answer
Level 13

You're passing a variable called $results to your view, and then trying to use a variable called $overview.

esorone's avatar

That's what i meant with a really stupid error.!!. I did check this zillion times.

Thanks you!

Cronix's avatar

You're retrieving ALL results to get a single user? Just get the one you're after.

$results = Result::where('user_id', Auth::id())->with('user');

Please or to participate in this conversation.