当用户没有足够的余额时,尝试使用消息重定向到上一页。 控制器:
if ($balance[0] > $kitap_baha[0]) {
$userkitap = new UlanyjyKitap();
$userkitap->user_id = Auth::id();
$userkitap->yarysh_id = $id;
$userkitap->save();
$galan = $balance[0] - $kitap_baha[0];
$user = User::find(Auth::id());
$user->balance = $galan;
$user->save();
return response()->download($downloads[0]);
} else {
return redirect()->back()->with('status', 'Balansyňyz ýeterlik däl');
}
查看:
@if (session('status'))
<div style="margin-top: 20px;">
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Bagyşlaň!</strong> {{ session('status') }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
</div>
@endif
dd($balance, $kitap_baha);
的结果是:
Collection {#311 ▼
#items: array:1 [▼
0 => 7.0
]
}
Collection {#303 ▼
#items: array:1 [▼
0 => 10.0
]
}
$balance
-用户余额
$kitap_baha
-书的价格
它正确返回,但是我认为没有会话。
我在这里做错什么了吗?