我正在开发一个主布局。应该提供从管理面板动态添加菜单和子菜单。我已将菜单和子菜单名称存储在数据库中。我已经在路径文件中静态分配了已知菜单的路由。
如何将路线分配给从管理面板动态创建的新菜单?此外,如何动态创建文件(查看文件),以便路由指向该文件。
基本上到现在为止我已经做了以下事情:
Route::get('/', 'PagesController@getIndex')->name('index');
Route::get('/contact', 'PagesController@getContact')->name('contact');
Route::get('/about', 'PagesController@getAbout')->name('about');
Route::get('/download', 'PagesController@getDownload')->name('download');
Auth::routes();
Route::get('/home', 'HomeController@index');
Route::resource('menus', 'MenuController');
Route::resource('submenus', 'SubmenuController');
public function index()
{
$menus = Menu::all();
return view('menus.index')->withMenus($menus);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('menus.create');
}
public function store(Request $request)
{
$this->validate($request,[
'menu_name' => "required|min:3|unique:menus,menu_name"
]);
$menu = new Menu;
$menu->menu_name = $request->menu_name;
$menu->save();
Session::flash('success', 'Menu successfully added!');
return redirect()->route('menus.index');
}
public function destroy($id)
{
$menu = Menu::find($id);
$menu->delete();
Session::flash('success', 'Menu was successfully deleted!');
return redirect()->route('menus.index');
}