-1

Below is the function to edit categories.

public function edit_categories(Request $request, $id){
                $category_datails=Category::where(['id'=>$id])->first();
    return view('admin.categories.edit_categories')->with(compact($category_datails));
   }

this is blade file

        <form class="form-horizontal" method="post" action="{{ Url('admin/edit-category') }}" name="add_category" id="add_category" novalidate="novalidate">   {{ csrf_field() }}
          <div class="control-group">
            <label class="control-label">Category Name</label>
            <div class="controls">
              <input type="text" name="category_name" id="category_name" value="{{ $category_datails->name }}">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label">Description</label>
            <div class="controls">
          <textarea type="text" name="Description" id="Description" value="{{ $category_datails->description }}"> </textarea>
            </div>
          </div>
          <div class="control-group">
            <label class="control-label">Url</label>
            <div class="controls">
              <input type="text" name="url" id="url" value="{{ $category_datails->id }}">
            </div>
          </div>
          <div class="form-actions">
            <input type="submit" value="AddCategory" class="btn btn-success">
          </div>
        </form>

My question is how to solve Undefined variable in category_datails. Any suggestions are welcome.

tereško
  • 58,060
  • 25
  • 98
  • 150
user9697323
  • 201
  • 3
  • 6

1 Answers1

1

compact is a PHP function: http://php.net/manual/en/function.compact.php

You need to pass it the variable name as a string ('category_datails'):

compact() takes a variable number of parameters. Each parameter can be either a string containing the name of the variable, or an array of variable names. The array can contain other arrays of variable names inside it; compact() handles it recursively.

public function edit_categories(Request $request, $id){ 
    $category_datails=Category::where(['id'=>$id])->first(); 
    return view('admin.categories.edit_categories')->with(compact('category_datails')); 
}
Bluetree
  • 1,324
  • 2
  • 8
  • 25
Ben Dubuisson
  • 727
  • 13
  • 38