我有这个编辑表单,后退按钮不起作用。因此,当我单击后退按钮时,它会显示此错误
尝试获取非对象的属性“名称”(查看:C:\ xampp \ htdocs \ Eguide \ resources \ views \ building.blade.php)
这是我的createOffice的后退按钮我尝试将它应用到我的EditOffice后台按钮并且它不起作用:
<a href="{{ route('building', ['id' => $id] ) }}" class="btn btn-default">Back</a>
另外,如何点击UpdateOffice按钮返回办公室列表的页面?
以下是代码
OfficeController.php
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();
\Session::flash('building_flash', 'Created successfully!');
return redirect()->back();
}
/**
* 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();
}
}
PageController.php
class PageController extends Controller
{
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);
} }
Building.blade.php
@extends('layouts.main')
@section('title',$building->name)
@section('css')
@stop
@section('content')
<div class="officebg">
<link href="https://fonts.googleapis.com/css?family=Anton" rel="stylesheet">
<div class="Bldgttl">
<div class="container">
<div class="row">
<div class="col-lg-12">
<img src="{{URL::to('/assets')}}/{{$building->picture}}" alt="" style="height:300px; width:500px;">
</div>
</div>
<div class="row">
<div class="col-lg-12">
{{$building->name}}
</div>
</div>
</div>
</div>
<div class="rows">
<div class="col-md-6 col-md-offset-3">
<div class="col-xs-4 col-md-6">
@if(!Auth::guest())
<a href="{{route('createofficeform', $building->id)}}" class="btn btn-primary btn-md">Create an Office</a>
@endif
</div>
{!! Form::open(['method'=> 'GET','url'=>'offices','role'=>'search']) !!}
<div class="input-group col-xs-4 col-md-6" >
<input type="text" name="search" class="form-control" placeholder="Search...">
<span class="input-group-btn">
<button type="submit" class="btn btn-info btn-md">Search</i>
</button>
</span>
</div>
{!! Form::close()!!}
<hr>
<table class="table">
<thead>
<th>Office Name</th>
<th>Office Floor</th>
</thead>
<tbody>
@foreach($offices as $office)
<tr>
<td>{{$office->name}}</td>
<td>{{$office->floor}}</td>
<td class="a">
@if(!Auth::guest())
<a href="{{route('editofficeform', $office->id)}}" class="btn btn-success btn-sm">Edit</a>
<a href="{{route('deleteoffice', $office->id)}}" class="btn btn-danger btn-sm">Delete</a>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
@endsection
路线
Route::get('building/{id}/offices/edit', 'OfficeController@edit')->name('editofficeform');
Route::post('building/{id}/offices/edit', 'OfficeController@update')->name('editoffice');
Route::get('/', 'BuildingController@index')->name('index');
Route::get('building/{id}', 'PageController@show')->name('building');
Route::get('office/{id}', 'OfficeController@show')->name('officeMenu');
Route::get('offices', 'OfficeController@index');
答案 0 :(得分:0)
您可以使用控制器中的back()命令返回上一页。
Model::create()
答案 1 :(得分:0)
你可以用这个
return back()->with('success', 'message success');;