Murtaza Murtaza - 1 year ago 138
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download