Novalink Novalink - 1 year ago 90
PHP Question

Laravel - Check query execution after attach() and detach()

After I execute this


or this


how do I make sure they actually get executed? In the first case it returns void, but also it saves automatically so I cannot use the save function to check it. In the second case it returns int, but what does it represent?

Answer Source

You do it with try/catch and DB::transaction/commit/rollback.

    \DB::transaction(function() use($shop, $article_id) {

} catch (\Exception $e) {

    return redirect()->back()->withErrors(collect($e->getMessage()));