vendredi 29 juin 2018

How to inherit connection using Laravel 5.6

i have 3 Adressen db's they all have excat same structure. I'm changing the connection with the static method on(....) when the variable $mandant changes. This is working but now i need to eager load several different relationships in a single operation. Is it possible to inherit the connection from the parent ?

this is my controller:

class DatasheetController extends Controller
{

    public function getMandant($mandant)
    {
        ....
    }

    public function show($mandant, $adresse)
    {

        $address = Adressen::on($this->getMandant($mandant))->find($adresse);

        dd($address->with('Kontokorrent')->get());

        return view('addresses.show', compact('address'));

    }

}

here my relationship:

class Adressen extends Model
{

    protected $primaryKey = 'Adresse';
    protected $table = 'Adressen';
    public $incrementing = false;
    public $timestamps = false;

    public function kontokorrent()
    {

        return $this->hasOne(Kontokorrent::class, 'Adresse');

    }

}

--

class Kontokorrent extends Model
{

    protected $primaryKey = 'Adresse';
    protected $table = 'Kontokorrent';
    public $incrementing = false;
    public $timestamps = false;


    public function address()
    {

         return $this->belongsTo(Adressen::class, 'Adresse');

    }

}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2yPUtXz
via IFTTT

Aucun commentaire:

Enregistrer un commentaire