我已经在网站上动态创建了菜单,但想在菜单下添加子菜单,但没有得到结果。
型号:子类别
`
命名空间App \ Http \ Controllers;
使用App \ Subcategory; 使用Illuminate \ Http \ Request;
使用App \ Category; 使用会话;
class subCategoriesController扩展了Controller { / ** *显示资源清单。 * * @return \ Illuminate \ Http \ Response * / 公共功能index() { 返回视图('admin.Subcategory.index')-> with('subcategories',Subcategory :: all()); }
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('admin.Subcategory.create')->with('subcategories', Subcategory::all())->with('categories', Category::all());
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'sub_cat_name' =>'required',
'sub_cat_id' => 'required'
]);
$data=[
'sub_cat_id'=>$request->sub_cat_id,
'sub_cat_name'=>$request->sub_cat_name,
];
$subcategory=Subcategory::create($data);
Session::flash('success', 'Subcategory has created successfully');
return redirect()->back();
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$subcategory=Subcategory::find($id);
return view('admin.Subcategory.edit')->with('subcategories', $subcategory)->with('subcategory', $subcategory);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$subcategory=Subcategory::find($id);
$subcategory->sub_cat_name=$request->sub_cat_name;
$subcategory->sub_cat_id=$request->sub_cat_id;
$subcategory->save();
Session::flash('success', 'SubCategory updated successfully');
return redirect()->route('categories');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$subcategory=Subcategory::find($id);
$subcategory->delete();
Session::flash('success', 'Subcategory has created successfully');
return redirect()->back();
}
}