Murtaza Murtaza - 9 months ago 60
SQL Question

Laravel fetch data from mysql table

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.


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