Reputation: 2191
Works perfectly in routes but does not work in the controller. What might be wrong?
public function index()
{
$positions = DB::table('position')
->join('company', 'position.company_id', '=', 'company.id')
->select('position.*', 'company.name')
->get();
// Just to check if it's working
print_r($positions);
}
Upvotes: 1
Views: 46
Reputation: 5169
You need to import the DB
facade.
You'll want to import the full namespace for this facade in the event that it's removed from the app.aliases
array.
use Illuminate\Support\Facades\DB;
Upvotes: 0
Reputation: 163948
You should add this to your controller:
use DB;
Or you can use this clause:
$positions = \DB::table('position')...
Controller just can't find DB
class, because you didn't show it the path to DB
.
Upvotes: 2