0

i am trying to fetch the values from database and show it on dropdown..while i am trying this i got this error undefined variable usertype..i can't understand where is the mistake..i am new to laravel framework..

Here is my controller:

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

}

Here is my view dropdown:

<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>

Can anyone help me..

3
  • there are 2 return in your function.. second one will never execute Commented Mar 21, 2017 at 6:06
  • why it will never execute? Commented Mar 21, 2017 at 6:07
  • I don't have any idea about laravel but in any programming language.. The first return statement that is executed will terminate the function and its value will be used Commented Mar 21, 2017 at 6:11

1 Answer 1

1

Try changing the variable name in compact function

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

}

And also remove the second return statement as it will never execute.

Sign up to request clarification or add additional context in comments.

3 Comments

Undefined variable: usertype (View: /var/www/html/hr_portal/resources/views/auth/register.blade.php)
is there anything we have to write in model?
dev please tell me the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.