Eloquent query builder - hasOne error

It drives me crazy. I have 2 tables;

  • explanations and
  • transactions.

In the models folder I have transaction.php

andexplanation.php.

transactions.php:

<?php

class Transaction extends Eloquent {

    public function explanation()
    {
        return $this->hasOne('Explanation');
    }

}

      

explanation.php

<?php

class Explanation extends Eloquent {



}

      

I'm just calling

Transaction::find(18)->explanation()->first();

      

The error I am getting is

The [hasone] method is not defined in the Query class

Can anyone see where I am going wrong?

+3


source to share


1 answer


Just figured out, read the wrong documentation.

Laravel 4.x

$this->hasOne();

      



Laravel <4.x

$this->has_one();

      

+4


source







All Articles