[Vuejs]-Save data in 2 different tables with laravel

3👍

You can use observers for this. Add this in your Article model:

protected static function boot()
    {
        parent::boot();
        // this triggers everytime an Article model is saved
        static::saved(function (Article $article) {
            $history = new History();
            $history->nombre = $article->nombre;
            $history->precio_proveedor = $article->precio_proveedor;
            $history->stock = $article->stock;
            $history->save();
        });
    }

Reference: https://www.larashout.com/how-to-use-laravel-model-observers

Leave a comment