Ich möchte ein dynamisches Menü mit Untermenüs erstellen. Wird Level1, Level2, Level3 sein.Aufruf zu undefinierter Methode Illuminate Database Query Builder :: has_many()
Aber ich bekomme diese Fehlermeldung: Call to undefined Methode Illuminate \ Database \ Abfrage \ Builder :: has_many() und Call to undefined Methode Illuminate \ Database \ Abfrage \ Builder :: has_many() (Ausblick: C : \ xampp \ htdocs **** \ resources \ views \ test.blade.php)
Dies ist, was ich bisher:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class WorkoutLevel1 extends Model
{
protected $table ='workout_level1s';
protected $fillable = ['title','icon','order_no'];
public function workoutlvl2(){
return $this->has_many('WorkoutLevel2');
}
}`
`
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class WorkoutLevel2 extends Model
{
protected $table = 'workout_level2s';
public function workoutlvl1(){
return $this->belongs_to('WorkoutLevel1');
}
public function workoutlvl3(){
return $this->has_many('WorkoutLeve3');
}
protected $fillable = ['title','order_no'];
}
`
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class WorkoutLevel3 extends Model
{
protected $table = 'workout_level3s';
public function workoutlvl2(){
return $this->belongs_to('WorkoutLevel2');
}
protected $fillable = ['title','order_no'];
}
Die Route:
Route::get('/menu', function() {
$lvl1s = App\WorkoutLevel1::all();
return View::make('test',compact('lvl1s'));
});`
Der Blick`
<div class="categories">
<!-- // left menu.... -->
<ul class="main">
@foreach($lvl1s as $lvl1)
<li><a href="">{{$lvl1->title}}</a></li>
@foreach($lvl1->workoutlvl2->take(2) as $lvl2)
<li><a href="">{{$lvl2->title}}</a></li>
@endforeach
@endforeach
</ul>
</div>
Vielen Dank! Ich habe nicht aufgepasst. :-) – codi05ro