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:
parent
27778dc56a
commit
e3eb880368
@ -14,7 +14,7 @@ class MenuController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('menus')
|
||||
return view('menus.index')
|
||||
->with('menus', Menu::get()
|
||||
->random(7)
|
||||
->shuffle());
|
||||
@ -27,7 +27,7 @@ class MenuController extends Controller
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
return view('menus.create');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,7 +38,8 @@ class MenuController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
Menu::create($request->only(['title']));
|
||||
return redirect()->route('menus.index');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,4 +8,6 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Menu extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['title'];
|
||||
}
|
||||
|
12
resources/views/menus/create.blade.php
Normal file
12
resources/views/menus/create.blade.php
Normal 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>
|
@ -2,3 +2,5 @@
|
||||
@foreach($menus as $menu)
|
||||
<li>{{ $menu->title }}</li>
|
||||
@endforeach
|
||||
|
||||
<p><a href="{{ route('menus.create') }}">Nouveau</a></p>
|
Loading…
Reference in New Issue
Block a user