mardi 29 octobre 2019

BadMethodCallException : Method Illuminate\Database\Query\Builder::offers does not exist

I am trying to do php artisan db:seed on Laravel 5.6.39 and getting an error:

BadMethodCallException : Method Illuminate\Database\Query\Builder::offers does not exist.

Offer Model code:

namespace App;

use Illuminate\Database\Eloquent\Model;

class Offer extends Model
{
    protected $guarded = [];

    public function task()
    {
        return $this->belongsTo(Task::class);
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

}

Task Model

public function offers()
{
    return $this->hasMany(Offer::class);
}

Databaseseeder file

factory(App\Task::class, 10)->create()->each(function ($task) {
    return $task->offers()->save(factory(App\Offer::class)->make());
});

What am I not doing right?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire