jeudi 22 novembre 2018

I can not make a query with Laravel

Good morning I am having a trouble while trying to create a simple query with Eloquent.

This is mi colonia model:

class Colonia extends Model
{
    protected $table = 'catalogo_colonias';   

    public function city()
    {
        return $this->belongsTo('App\City', 'ciudades_id');
    }
}

if I do.

$response = Colonia::find(1)->city;

I am getting a response but i do not want to find by id, I am trying to make something like this.

$response = Colonia::where('codigo_postal', $codigo_postal)->city;

but it throws me an error.

Undefined property: Illuminate\Database\Eloquent\Builder::$city

and it is declared above as you can see, I guess that is a syntax problem, hope you could help me.

Thank you, greetings.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire