More of a relationship in the same model

Asked

Viewed 131 times

0

My client class has a relationship one-to-one with endereco and one-to-Many with contacts. How would be the functions in Cliente to function? and in Migrate?

1 answer

0


Look at an example of One to Many and of course more examples and documentation on Laravel.com

<?php

class Category extends Eloquent {

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'categories';

    /**
     * Whether or not to enable timestamps.
     *
     * @var bool
     */
    public $timestamps = false;

    /**
     * Defines a one-to-many relationship.
     *
     * @see http://laravel.com/docs/eloquent#one-to-many
     */
    public function posts()
    {
        return $this->hasMany('Post');
    }

    /**
     * Defines a has-many-through relationship.
     *
     * @see http://laravel.com/docs/eloquent#has-many-through
     */
    public function comments()
    {
        return $this->hasManyThrough('Comment', 'Post');
    }

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.