samedi 3 février 2018

Undefined variable: expenses_category in Laravel

I tried to edit the data been fetched from the database in laravel by passing the id through the url but everytime I click the url to go to edit page I received:

"Undefined variable: expenses_category (View: C:\xampp\htdocs\Tailor\core\resources\views\expensesCat\edit.blade.php)"

Link to the edit.blade

<a href="" class="btn btn-xs btn-info">Edit</a>

Here is the 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="">
                    {!! 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">
                            
                        </p>
                    @endif
                </div>
            </div>

        </div>
    </div>

    {!! Form::submit('Update', ['class' => 'btn btn-danger']) !!}
    {!! Form::close() !!}
@stop

For 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'));
    }

What could have been the error?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire