I am trying to use DB
class to run query. I have used it in my controller like this:
use \DB;
And I am using it in my code like this:
$changeCar = DB::select(DB::raw($query));
I have tried including it like this:
use Illuminate\Support\Facades\DB
But still the same. Also, tried it with the backslash in the code and not including it like this:
$changeCar = \DB::select(\DB::raw($query));
My Code:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use \DB;
class TicketsController extends Controller
{
public function myTickets()
{
$user = Auth::user();
$changeCar = DB::select(DB::raw($query));
}
}
Still the same. What am I doing wrong here? Any help?
PS: My laravel
version is 5.4.33
DB
is a facade in Laravel. So just doing Use DB;
should work. Can you check if you have opcache
enabled on your php.ini ?
Look up php.ini
for opcache_enabled=1
and change the value to 0. Then restart your nginx/apache server and try again.
我通过将以下内容添加到我的模型顶部来使其工作:
use Illuminate\Support\Facades\DB;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.