如何调用此后退按钮路线,Laravel [英] How to call this route for back button , Laravel
本文介绍了如何调用此后退按钮路线,Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Createoffice表单和Editoffice表单的后退按钮上遇到问题,它没有返回到列出办公室的页面
I'm having problems with the back button of my Createoffice form and Editoffice form it doesn't goes back to the page where the offices are listed
我尝试使用这个:
<a href="{{ route('building', $building->id) }}" class="btn btn-default">Back</a>
但是不起作用,这是错误:
but nah its not working here's the error:
Undefined variable: building (View: C:\xampp\htdocs\Eguide\resources\views\createoffice.blade.php)
这是我的路线:
Route::get('building/{id}', 'PageController@show');
Route::get('office/{id}', 'OfficeController@show')->name('officeMenu');
Route::get('offices', 'OfficeController@index');
Route::get('building/{id}/offices/create', 'OfficeController@create')->name('createofficeform');
Route::post('building/{id}/offices/create/store', 'OfficeController@store')->name('createoffice');
Route::get('building/{id}/offices/edit', 'OfficeController@edit')->name('editofficeform');
Route::post('building/{id}/offices/edit', 'OfficeController@update')->name('editoffice');
这就是我显示数据的方式
This is how I make the data display
PageController.php
PageController.php
public function buildings(){
$buildings = Building::paginate(10);
return view('buildings')->with('buildings', $buildings);
}
public function show($id){
$building = Building::find($id);
$offices = Office::where('building_id', $id)->orderBy('floor')->get();
return view('building')->with('building', $building)->with('offices', $offices);
} }
OfficeController.php
OfficeController.php
类OfficeController扩展了Controller {
class OfficeController extends Controller {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$search = \Request::get('search');
$offices = Office::where('name','like','%'.$search.'%')->get();
return view('search')->with('offices', $offices)->with('search', $search);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create($id)
{
return view('createoffice')->with('id', $id);
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request, $id)
{
$office = new Office();
$office->name =$request->officename;
$office->floor = $request->floor;
$office->building_id = $id;
$office->save();
return redirect()->back();
\Session::flash('building_flash', 'Created successfully!');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$office = Office::find($id);
return view('office')->withOffice($office);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$office = Office::find($id);
return view('editoffice')->withOffice($office)->with('id',$id);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$office = Office::find($id);
$office->name =$request->officename;
$office->floor = $request->floor;
$office->update();
\Session::flash('building_flash', 'Updated successfully!');
return redirect()->back();
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$office = Office::find($id);
$office->delete();
\Session::flash('building_flash_delete', 'Deleted successfully!');
return redirect()->back();
}
推荐答案
命名您的路线
Route::get('building/{id}', 'PageController@show')->name('building');
并将变量作为第二个参数传递给route
and pass the variable as second argument to route
<a href="{{ route('building', ['id' => $id] ) }}" class="btn btn-default">Back</a>
这篇关于如何调用此后退按钮路线,Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文