Here is my form:
<form method="POST" action="{{ route('item.deactivate', [ 'item' => $item->id ]) }}">
@csrf
<button type="submit">Deactivate</button>
<input type='submit' value="Deactivate" onclick="return confirm('Deactivate?')"/>
</form>
As you can see, i included 2 versions of a Deactivate button.
First button does not show a confirmation pop-up, but it does show a confirmation message AFTER deactivation of the item.
Second button is supposed to do exactly the same, aside from the fact that it does show a confirmation pop-up. BUT i don't understand why, when i use this second button, it doesn't display a confirmation message AFTER.
Whether i click on button 1 or button 2, the item is actually deactivated, so the main part works.
But i am curious to know why i can't show a session message with the second button...
Here is the function in my controller:
public function deactivate(Item $item)
{
if($item->user_id == auth()->user()->id)
{
$item->update([
'active' => 0
]);
return redirect()->back()->with('message', 'Item deactivated!');
}
else
{
abort(403);
}
}
<?php var_dump(session()->all()); ?>
var_dump when i use the first button:
array(6) { ["_token"]=> string(40) "NkADD5mgWRG9AJFofDmtJGQfSExUyk7mcmBODpWO" ["_flash"]=> array(2) { ["old"]=> array(1) { [0]=> string(7) "message" } ["new"]=> array(0) { } } ["_previous"]=> array(1) { ["url"]=> string(29) "http://127.0.0.1:8000/account" } ["login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d"]=> int(1) ["url"]=> array(1) { ["intended"]=> string(45) "http://127.0.0.1:8000/virtual_assistant_tools" } ["message"]=> string(19) "Item deactivated!" }
var_dump when i use the second button:
array(5) { ["_token"]=> string(40) "NkADD5mgWRG9AJFofDmtJGQfSExUyk7mcmBODpWO" ["_flash"]=> array(2) { ["old"]=> array(0) { } ["new"]=> array(0) { } } ["_previous"]=> array(1) { ["url"]=> string(29) "http://127.0.0.1:8000/account" } ["login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d"]=> int(1) ["url"]=> array(1) { ["intended"]=> string(45) "http://127.0.0.1:8000/virtual_assistant_tools" } }