【发布时间】:2019-01-03 00:31:31
【问题描述】:
我遇到了以下问题:我的 laravel 应用程序中有切换器,它向控制器发出请求,控制器实际上设置了表单输入中传递的会话参数并返回 back() 响应。问题是有时它被错误地填充并混合了两个变量。
我有 whi 变量 account_id 和 building_id(最后根据 account_id 计算),在这种情况下,building_id 等于 account_id 并导致异常。
详细代码(控制器):
public function switchHeaders(Request $request) {
$account = Account::find($request->get('account_id'));
if ($request->has('account_id') && $account !== null) {
session([
'account_id' => $account->id,
'building_id' => $account->building_id,
]);
} else {
session([
'account_id' => null,
'building_id' => null,
]);
}
return back();
谁能告诉我如何在这里找到问题
【问题讨论】: