我正在尝试制作一个网站,您可以在其中上传游戏并在主页上查看它们,但是因为我需要一个两步表单,所以我无法将它们直接发送到数据库。
我的控制器:
public function createstep1(Request $request)
{
$naam = $request->session()->get('naam');
return view('games.game',compact('naam', $naam))->with('games', game::all());
}
public function postcreatestep1(Request $request)
{
$validatedData = $request->validate([
'naam' => 'required',
'geslacht' => 'required',
]);
if(empty($request->session()->get('naam'))){
return redirect('/game');
}else{
$naam = $request->session()->get('naam');
$naam->fill($validatedData);
$request->session()->put('naam', $naam);
}
return redirect('/newgame');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create(Request $request)
{
$naam = $request->session()->get('naam');
return view('games.newgame',compact('naam',$naam));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$game= new Game();
$game->game= $request['game'];
$game->naam= $request['naam'];
$game->geslacht= $request['geslacht'];
$game->save();
return redirect('/game');
}
<div id="newgame" style="height: 500px; width: 250px; float: left;">
<form method="post" name="naam">
@csrf
<input id="naam" name="naam" placeholder="naam">
<select name="geslacht" type="text">
<option name="man">man</option>
<option name="vrouw">vrouw</option>
</select>
<a type="submit"><button>volgende</button></a>
</form>
</div>
<div id="games" style="float: right">
@foreach($games as $game)
{{$game->game}} <br><br>
@endforeach
</div>
我希望它会在数据库中删除游戏 + 姓名和性别,但实际代码给出了一条错误消息。这项工作适用于学校,但如果您有建议或可以帮助我解决问题,他们将无法帮助我。
倚天杖