所以我的问题是,我有一个表单,我希望这个表单具有默认值,这就是我分配$ s变量的原因。这个变量来自Controller,但它总是给出错误;
(2/2)ErrorException未定义变量:s(查看:C:\ xampp \ htdocs \ X-GOTL \ resources \ views \ actions \ activity.blade.php)
我知道这不行,因为在开始时没有默认值,因为它还没有由控制器发送。我尝试了一些ifs来解决它,但无论如何它不起作用。此$ s值也等于此表单中所选值的数量。我有什么想法可以解决这个问题吗?
{!! Form :: select('number',['1'=>'KoşuyaÇıkmak','2'=>'瑜伽 Yapmak'],$ s)!!}
这是控制器中的代码。
$activity = $request->number;
$user_stat = Auth::user()->stat;
$job_user = Auth::user()->stat;
$userInfo = Auth::user();
$id = $userInfo->id;
$user = User::find($userInfo->id);
if($activity == 1){
$s = $request->number;
$user_stat->str = Auth::user()->stat->str + 4;
$user_stat->dex = Auth::user()->stat->dex + 4;
$job_user->save();
return redirect('/activity')->with('stat', '4 Güç ve 4 Beceri Kazandın!')->with(compact('s'));
}
elseif($activity == 2){
$s = $request->number;
$user_stat->str = Auth::user()->stat->str + 4;
$user_stat->int = Auth::user()->stat->int + 4;
$job_user->save();
return redirect('/activity')->with('stat', '4 Güç ve 4 Zeka Kazandın!')
->with(compact('s'));
}
答案 0 :(得分:0)
答案很简单..只是添加withInput()
返回重定向('/ activity') - > with('stat','xxx') - > withInput();