2017-03-21 1 views
0

나는 데이터베이스에서 값을 가져 와서 드롭 다운에 표시하려고합니다.이 오류는 undefined variable usertype..i이 어디서 오류인지 이해할 수 없습니다.laravel5.4에서 정의되지 않은 변수

<div class="form-group"> 
        <label for="cat">User Type</label> 
         <select class="form-control" name="user_type_id"> 
         @foreach($usertype as $user) 
         <option id="user_type_Id" value="{{$user->id}}" selected="selected">{{ $user->type }}</option> 
         @endforeach 
         </select> 
        </div> 

누군가가 나를 도울 수 ..

: 여기
public function get() { 
    $usertype = DB::table('user_type')->get(); 
    return View::make('/home')->with(compact('user_type')); 
    return $usertype; 

} 

내보기 드롭 다운입니다 : 여기

내 컨트롤러입니다 .. laravel 프레임 워크에 새로운 오전
+0

함수에서 2가 반환됩니다. 두 번째 실행은 결코 실행되지 않습니다 –

+0

왜 실행되지 않습니까? – bharathi

+0

laravel에 대해서는 알지 못하지만 모든 프로그래밍 언어에서 .. 처음 실행되는 return 문은 함수를 종료하고 해당 값이 사용됩니다. –

답변

1

는 컴팩트 한 기능에

public function get() { 
    $usertype = DB::table('user_type')->get(); 
    return View::make('/home')->with(compact('usertype')); 
    return $usertype; 

} 

를 변수 이름을 변경 시도하고 또한 실행되지 않을 것 같은 두 번째 return 문을 제거합니다.

+0

여전히 동일한 오류가 있습니까? – bharathi

+0

정의되지 않은 변수 : usertype (보기 : /var/www/html/hr_portal/resources/views/auth/register.blade.php) – bharathi

+0

모델에 쓸 내용이 있습니까? – bharathi