Support the ongoing development of Laravel.io →
posted 8 years ago
Eloquent
Last updated 2 years ago.
0

Add namespace App;

at the top of your Model like so

namespace App;

class Cat extends Model
{
    //
    protected $fillable = [
        'name', 'date_of_birth', 'breed_id',
    ];
    public function breed(){
        return $this->belongsTo('Breed');
    }
}

0

I did it and still dont work :( Maybe with Breed Model is some not fine, like in $this->hasMany('Cat'); because error is in Model.php in vendor laravel in this:

public function hasMany($related, $foreignKey = null, $localKey = null)
    {
        $foreignKey = $foreignKey ?: $this->getForeignKey();

        $instance = new $related;

        $localKey = $localKey ?: $this->getKeyName();

        return new HasMany($instance->newQuery(), $this, $instance->getTable().'.'.$foreignKey, $localKey);
    }

in $instance = new $related;

0

Sign in to participate in this thread!

Eventy

Your banner here too?

gargi369 gargi369 Joined 7 Apr 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.

© 2024 Laravel.io - All rights reserved.