JackSlayer94 JackSlayer94 - 1 year ago 69
MySQL Question

Populate data from MySQL on Laravel Page

I have a bootstrap drop down on a Laravel page(Sign Up page) and would like to populate it using data from my MySQL database. So in my routes, I have something like this:

Route::get('/signup', [
'uses' => 'SigninSignupController@getSignup',
'as' => 'signup'

And in my SigninSignupController:

public function getSignup(){
$users = DB::table('users')->get();
return view('pages.signup', ['users' => $users]);

In my signup.blade.php:

@foreach ($users as $user)
<option> {{ $user->orgid; }} </option>

But I get an error like this : http://pastebin.com/543VGaq9

In my SigninSignupController, I have these:

use Illuminate\Support\Facades\DB;
namespace App\Http\Controllers;

What am I doing wrong? Can someone point it out?

Answer Source

Change namespace and use to:

namespace App\Http\Controllers;

use DB;

Also, you don't need to use ; in Blade templates, so it should look like:

{{ $user->orgid }}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download