하위 메뉴가있는 동적 메뉴를 만들고 싶습니다. Level1, Level2, Level3이됩니다.
하지만이 오류가 발생합니다. 정의되지 않은 메서드 Illuminate \ Database \ Query \ Builder :: has_many () 호출 및 정의되지 않은 메서드 Illuminate \ Database \ Query \ Builder :: has_many () 호출 (보기 : C : \ xampp \ htdocs ** ** \ resources \ views \ test.blade.php)
이것이 내가 지금까지 가지고있는 것입니다.
<?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'];
}
경로:
Route::get('/menu', function () {
$lvl1s = App\WorkoutLevel1::all();
return View::make('test',compact('lvl1s'));
});`
보기`
<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>
오류 내용 :
정의되지 않은 메서드 Illuminate \ Database \ Query \ Builder :: has_many () 호출
그래서, 대신 has_many
에 hasMany
(와 belongs_to
함께 belongsTo
)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다