hi, im starting to use laravel 5.5
i would like to make a query by query bulider.
i cannot use static methods from DB class like 'table', because it's not defined.
basic example
namespace App\Http\Controllers;
use App\Site;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\DB;
class SiteController extends Controller {
public function actionIndex(Request $request) {
$label = $request->route('label');
$site = DB::table('sites')->where('label', 'like', $label);
return view('site.index')->with('site', $site);
}
}
where did i go wrong?
Try use DB;
at the top of your file instead of directly using the Facade class
nothing changed.
phpstorm claims that class DB is undefined
namespace App\Http\Controllers;
use App\Site;
use Illuminate\Http\Request;
use DB;
class SiteController extends Controller {
public function actionIndex(Request $request) {
$label = $request->route('label');
if($label) {
$site = DB::table('sites')->where('label', 'like', $label);
return view('site.index')->with('site', $site);
}
else {
$collection = Site::all();
return view('site.index', compact('collection'));
}
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
how about this?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community