2

I have a controller in Laravel 5.0 like this-

    <?php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;
    use App\Http\Requests;
    use App\Http\Controllers\Controller;

    class CustomersController extends CustomerLayoutController
    {
        public function getDashboard()
        {
            return $this->view('layouts.customer.dashboard', []);
        }

        public function getTest()
        {
            return $this->view('layouts.admin.webinar', ['qustions' => DB::table('qustions')->get()]);
        }
    }

So, I want to pass DB::table('qustions')->get() as a parameter to my views, but I m getting error.

What I am doing wrong?

2
  • 1
    What error are you getting? It's pretty important to know that Commented Sep 22, 2015 at 12:52
  • FatalErrorException in CustomersController.php line 18: Class 'App\Http\Controllers\DB' not found Commented Sep 22, 2015 at 12:55

1 Answer 1

3

You're getting an error because Laravel is searching the class is the wrong namespace (it's "appending" the class to the current class's namespace, if you note).

You either import the DB class with the use keywords:

 use Illuminate\Http\Request;
 use App\Http\Requests;
 use App\Http\Controllers\Controller;
 use DB;

or let it know that DB resides in the "global" application namespace, so call it with a backslash:

return $this->view('layouts.admin.webinar', ['questions' => \DB::table('qustions')->get()]);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for helping me
It's worth mentioning that inside the config/app.php resides a key aliases which will map 'DB' => 'Illuminate\Support\Facades\DB'.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.