2 테이블과 피벗 테이블이 있습니다. 테이블의 구조는 다음과 같습니다. laravel을 사용하여 many에서 many로 데이터를 검색
users table:
id username password
1 admin xyzasd
roles table:
id name
1 role1
2 role2
role_user table:
id user_id role_id
1 1 1
2 1 2
내 사용자 모델 :
class User extends Basemodel{
public static $table = 'users';
public static $timestamps = true;
public function roles()
{
return $this->has_many_and_belongs_to('Role');
}
public static function menu(){
$roles = User::find(1)->roles()->get();
return $roles;
}
}
내 컨트롤러 :
public function get_index()
{
return View::make('home.index')
->with('title','testing many to many')
->with('menu',User::menu());
}
내가이 문이 내 블레이드보기 파일
이 {{$ 메뉴}} 내가 얻을 모든 메시지입니다 배열, 레코드를 가져 오는 방법에 대한 안내를받을 수 있습니까?
: 같은
그런 다음보기에 당신은 멋진 물건을 할 수 있습니다. :)하지만 정말 당신의 도움에 감사드립니다 :) –