我尝试通过将id传递到url来编辑从laravel中的数据库中获取的数据,但每次我点击url转到我收到的编辑页面时都会:
"Undefined variable: expenses_category (View: C:\xampp\htdocs\Tailor\core\resources\views\expensesCat\edit.blade.php)"
链接到edit.blade
<a href="{{ url('admin/editCat',[$expenses_category->id]) }}" class="btn btn-xs btn-info">Edit</a>
这是edit.blade
@section('content')
<div class="portlet light bordered">
<h3 class="page-title">Expenses Categories</h3>
{!! Form::model($expenses_category, ['method' => 'PUT', 'route' => ['updateCat', $expenses_category->id]]) !!}
<div class="panel panel-default">
<div class="panel-heading">
Edit
</div>
<div class="panel-body">
<div class="row">
<div class="col-xs-12 form-group">
<input name="order_create_by" type="hidden" value="{{ Auth::user()->id }}">
{!! Form::label('name', 'Name*', ['class' => 'control-label']) !!}
{!! Form::text('name', old('name'), ['class' => 'form-control', 'placeholder' => '']) !!}
<p class="help-block"></p>
@if($errors->has('name'))
<p class="help-block">
{{ $errors->first('name') }}
</p>
@endif
</div>
</div>
</div>
</div>
{!! Form::submit('Update', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
@stop
对于web.php
Route::get('/editCat/{id}', 'ExpensesCategoriesController@editCat');
for ExpensesCategoriesController
public function editCat($id)
{
$expenses_category = ExpensesCategory::findOrFail($id);
return view('expensesCat.edit', compact('expenses_categories'));
}
可能是什么错误?
答案 0 :(得分:1)
将controller
功能更改为此 -
public function editCat($id)
{
$expenses_category = ExpensesCategory::findOrFail($id);
return view('expensesCat.edit', compact('expenses_category'));
}
你也需要在compact中使用相同的变量名。