2017-03-05 8 views
1

Bitte helfen Sie mir; Ich bin neu in Laravel und ich verstehe nicht, was ich falsch mache.Laravel undefine Variable: Kategorie

Hier ist meine Ansicht:

<div class="container"> 
    <h1>category and subcategory</h1> 
    <div class="row"> 
    <div class="col-md-10 col-md-offset-1"> 
     {!! Form::open(array('url' => '','files'=>true)) !!} {!! Form::token(); !!} 
     <div class="form-group"> 
     <label for="">category</label> 
     <select class="form-control input-sm" name="" id=""> 
      @foreach ($category as $category) 
      <option value="{{$category->id}}">{{$category->name}}</option> 
      @endforeach 
     </select> 
     </div> 
     <div class="form-group"> 
     <label for="">subcategory</label> 
     <select class="form-control input-sm" name="" id=""> 
      <option value=""></option> 
     </select> 
     </div> 
     </form> 
    </div> 
    </div> 
    <script type="text/javascript"> 
    $(document).ready(function() { 
      $("#category").on('change', function(e) { 
      console.log(e); 
      var cat_id = e.target.value; 
      $.get('/ajax-subcat/' + cat_id, function(data) { 
       //success data 
       console.log(data); 
      }) 
      }); 
    </script> 
</div> 
</div> 
</div> 

Hier ist meine Route:

Route::get('/', function() { 
    $category = \App\ category::all(); 
    return view('layouts.app') - > with('categories', $category); 
}); 
Route::get('/ajax-subcat', function() { 
    $category = \App\ category::all(); 
    $cat_id = Input::get('cat_id'); 
    $subcategory = subcategory::where('category_id', '=', $cat_id) - > orderBy('name', 'asc') - > get(); 
    return response() - > json($subcategory); 
}); 

Und das ist mein Fehlerlogdatei:

Error in ec195dc7ec967851481b4815c28c6879244d5d45. phpline 87: Nicht definierte Variable: Kategorie (Ansicht: C: \ xampp \ htdocs \ laravel \ ressourcen \ ansichten \ layouts \ app.blade.php) (Ansicht: C: \ xampp \ htdocs \ laravel \ ressourcen \ ansichten \ layouts \ app.blade .php) ec195dc7ec967851481b4815c28c6879244d5d45.php in Leitung 87 bei CompilerEngine-> handleViewException (Objekt (Error), '1') in der Leitung 44 PhpEngine.php bei PhpEngine-

Was diese Fehler verursacht?

Antwort

0

Versuchen Wechsel:

@foreach ($category as $category) 

zu:

@foreach ($categories as $category) 

hoffe, das hilft!