Menus : création possible via un formulaire. fixes #2

* ajout d'un lien "nouveau" sur la liste des menus
* création d'un formulaire de création d'un menu
* enregistrement du menu
This commit is contained in:
Olivier DOSSMANN 2021-04-28 19:05:04 +02:00
parent 27778dc56a
commit e3eb880368
4 changed files with 20 additions and 3 deletions

View File

@ -14,7 +14,7 @@ class MenuController extends Controller
*/ */
public function index() public function index()
{ {
return view('menus') return view('menus.index')
->with('menus', Menu::get() ->with('menus', Menu::get()
->random(7) ->random(7)
->shuffle()); ->shuffle());
@ -27,7 +27,7 @@ class MenuController extends Controller
*/ */
public function create() public function create()
{ {
// return view('menus.create');
} }
/** /**
@ -38,7 +38,8 @@ class MenuController extends Controller
*/ */
public function store(Request $request) public function store(Request $request)
{ {
// Menu::create($request->only(['title']));
return redirect()->route('menus.index');
} }
/** /**

View File

@ -8,4 +8,6 @@ use Illuminate\Database\Eloquent\Model;
class Menu extends Model class Menu extends Model
{ {
use HasFactory; use HasFactory;
protected $fillable = ['title'];
} }

View File

@ -0,0 +1,12 @@
<form method="POST" action="{{ route('menus.store') }}">
@csrf
<label for="title">Titre du menu</label>
<input id="title" name="title" type="text" class="@error('title') is-invalid @enderror">
@error('title')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<input type="submit" value="Nouveau menu">
</form>

View File

@ -2,3 +2,5 @@
@foreach($menus as $menu) @foreach($menus as $menu)
<li>{{ $menu->title }}</li> <li>{{ $menu->title }}</li>
@endforeach @endforeach
<p><a href="{{ route('menus.create') }}">Nouveau</a></p>