sergionc
1 month ago
150
5
Laravel

eloquent does not relate model

Posted 1 month ago by sergionc

Model Region

class Region extends Model { protected $fillable = [

    'nombre_region'
];

public function ciudad()
{
    return $this->belongsTo(Ciudad::class);
}

}

Model Ciudad

class Ciudad extends Model { protected $fillable = [

    'region_id','nombre_ciudad'
];

public function regions()
{
    return $this->hasMany(Region::class);
}

}

$ciudadeslista = Ciudad::all();

dd($ciudadeslista->regions->nombre_region);

Property [region] does not exist on this collection instance.

Please sign in or create an account to participate in this conversation.