0

By using the following code on my controller page, I am trying to fetch data from mysql database.

namespace App\Http\Controllers;

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

class productscontroller extends Controller
{
    public function index()
    {
        $Products = DB::table('products_description')->get();
        return view('products.index',compact($Products));
    }   
}

and receiving the following error.

FatalErrorException in productscontroller.php line 12:
Class 'App\Http\Controllers\DB' not found

I am following a laracast tutorial to fetch the data but not sure what I am doing wrong.

1 Answer 1

2

Either put use DB; or $Products = \DB::table('products_description')->get();

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

15 Comments

with $Products = \DB::table('products_description')->get(); it is giving the following error PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost'
Edit your .env file .. Provide database, username and password there
By using use DB; it is giving the following error syntax error, unexpected 'use' (T_USE)
I already configured "config > database.php". where should I find .env file you are talking about?
Which version of laravel are you using?
|

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.