validate([ 'name' => 'required|string|max:255', 'hex' => 'required|string|max:255' ]); $color = new Color(); $color->name = $request->name; $color->hex = $request->hex; $color->save(); return redirect()->route('colors.index'); } /** * Display the specified resource. */ public function show(string $id) { // show single color $color = Color::find($id); return view('colors.show', compact('color')); } /** * Show the form for editing the specified resource. */ public function edit(string $id) { // edit color $color = Color::find($id); return view('colors.edit', compact('color')); } /** * Update the specified resource in storage. */ public function update(Request $request, string $id) { // update color $color = Color::find($id); $color->name = $request->name; $color->hex = $request->hex; $color->save(); return redirect()->route('colors.show', $color->id); } /** * Remove the specified resource from storage. */ public function destroy(string $id) { // delete color $color = Color::find($id); $color->delete(); return redirect()->route('colors.index'); } }