samedi 26 décembre 2015

Many to Many Relationship Join Query between Two Table in Laravel 5.1

First User table have four columns: id ,first_name, last_name,password

my Address Table have four colmnns id , company_name,email , phone

Common Address_user Table:

enter image description here

My User Model Look Like This http://ift.tt/1JAsAfQ and my Address Model Look Like This

use Illuminate\Database\Eloquent\Model;

class Address extends Model
{
    protected $fillable = [
    'created_by',
    'company_name',
     'phone', 
     'email', 'address'
    ];
    public function users()
    {
        return $this->belongsToMany('App\Models\User');
    }
    public function getAddressListAttribute()
    {
        return $this->users->lists('id');
    }
}

now I need the all of address which login user is involved or connected

1:



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire