laravel 语法错误,意外的“使用”(T_USE)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42563229/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:27:14  来源:igfitidea点击:

syntax error, unexpected 'use' (T_USE)

phplaravellaravel-5

提问by cyber8200

I have a short PHP snippets on top of my blade file

我的刀片文件顶部有一个简短的 PHP 片段

<?php


use App\ImageWork, App\User, App\Skill, App\Contact, App\ActivityLog;

$images   = ImageWork::orderBy('created_at', 'desc')->get();
$users    = User::orderBy('created_at', 'desc')->get();
$logs     = ActivityLog::orderBy('created_at', 'desc')->get();
$skills   = Skill::orderBy('created_at', 'desc')->get();
$contacts = Contact::orderBy('created_at', 'desc')->get();

?>

I got this :

我懂了 :

syntax error, unexpected 'use' (T_USE)

when I don't add that line, I got this

当我不添加那条线时,我得到了这个

Class 'ImageWork' not found

What should I do now either way is wrong ?

我现在应该怎么做,无论哪种方式都是错误的?

Any hints / suggestions ?

任何提示/建议?

回答by brunohdaniel

Include the DB facade

包括数据库外观

use Illuminate\Support\Facades\DB;

And try to use that:

并尝试使用它:

$images   = DB::table('ImageWork')->orderBy('created_at', 'desc')->get();