Route [admin / update]未在Laravel中定义

时间:2018-02-04 09:37:35

标签: laravel laravel-5

我无法在Laravel中更新我的数据,这让我很头疼。每次我点击更新按钮时都会发生错误。

以下是错误:

"Route [admin/update] not defined. (View: C:\xampp\htdocs\Tailor\core\resources\views\expensesCat\edit.blade.php)"

这是edit.blade

<div class="portlet light bordered">
    <h3 class="page-title">Expenses Categories</h3>

   {!! Form::model($expenses_category, ['method' => 'POST', 'route' => ['admin/update', $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>

web.php

Route::post('/update/{id}', 'ExpensesCategoriesController@updateCat');

ExpensesCategoriesController

 public function updateCat(UpdateExpensesCategoriesRequest $request, $id)
    {
        $expenses_category = ExpensesCategory::findOrFail($id);
        $expenses_category->update($request->all());

         return redirect('admin/expenses_categories');
    }

2 个答案:

答案 0 :(得分:0)

您尝试按名称使用路线,但您没有命名。所以,将其改为:

'route' => ['admin.update', ....

并命名路线:

Route::post('/update/{id}', 'ExpensesCategoriesController@updateCat')->name('admin.update');

或者:

Route::post('/update/{id}', ['as' => 'admin.update', 'uses' => 'ExpensesCategoriesController@updateCat']);

答案 1 :(得分:0)

在表单中使用url -

{!! Form::model($expenses_category, ['method' => 'POST', 'url' =>'admin/update/'.$expenses_category->id]) !!}