lundi 14 février 2022

eloquent relationship from collection on different models

I have two models as activity and products each operation on the products model will log as audits on the activity table. products table has a few columns which are used to relate to other tables. the output of the activity table will be as follows

    "id" => 166
    "log_name" => "default"
    "description" => "ADMIN has updated PO# : 116"
    "subject_type" => "App\Models\Po"
    "event" => "updated"
    "subject_id" => 5
    "causer_type" => "po"
    "causer_id" => 1
    "product" => "{"old": {"id": 5, "qty": 238, "vendor_auto_id":15}, "new":{"id": 5, "qty": 500}}

I am able to get the category name by querying Product::with('vendor_auto_id') on the controller and querying on Model as follows

    public function vendor_auto_id(){
        return $this->hasOne('\App\Models\Vendor','id', 'vendor_auto_id');
    }

which returns the correct information. the question is I wanted to make a relationship on the Vendor table using the Activity model. can someone recommend the best solution?

following is the package I'm using to log activities on Laravel https://spatie.be/docs/laravel-activitylog/v4/introduction



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

Aucun commentaire:

Enregistrer un commentaire