Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent

I have two models. My first one is:

<?php namespace App;

use Illuminate\Database\Eloquent\Model;


class Fixture extends Model {

    public function match()
    {
        return $this->hasOne('App\Matchinfo');
    }

    public function result()
    {
        return $this->hasOne('App\Result');
    }

}

and the second one:

<?php namespace App;

use Illuminate\Database\Eloquent\Model;


class Matchinfo extends Model {

    protected $table =  'matchinfo';

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

}

When I run $fixture = Matchinfo::where('mdate','<','NOW()')->get(); it picks up the data just fine. However when I then try $fixture->fixture()->where('id','fixture_id')->get(); all I get is

FatalErrorException in DynamicPagesController.php line 15: Call to undefined method Illuminate\Database\Eloquent\Collection::fixture()

I'm new to relationships in eloquent so I'm really stuck. It looks like it should be ok. Can someone point me in the right direction please?

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

danjswade danjswade Joined 18 Feb 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.