E
E
EVOSandru62018-08-05 20:52:09
Laravel
EVOSandru6, 2018-08-05 20:52:09

Why is the simple :string method of the Eloquent model called as a relation in laravel?

Good afternoon,
There is a misunderstanding when calling the method of the Edition model .

namespace App\Entity\Vehicle;

use Illuminate\Database\Eloquent\Model;

class Edition extends Model
{
    public function brand()
    {
        return $this->belongsTo(Brand::class);
    }

    public function joke() :string
    {
        return 'hello';
    }
}

When calling methods in both cases:
$edition = Edition::findOrFail(1);
        dd($edition->joke());
        dd($edition->brand());

The following errors are thrown:
Method Illuminate\Database\Query\Builder::brand does not exist.
and
Method Illuminate\Database\Query\Builder::joke does not exist. It does not define the brand
connection , and the joke method takes it for a non-existent connection. Laravel - 5.6 Postgres - 9.6.9 What could be the reason?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vism, 2018-08-05
@EVOSandru6

Cheto you wised up that dd($edition); displays?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question