为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我的 @foreach 语句在 Laravel 中不起作用?

为什么我的 @foreach 语句在 Laravel 中不起作用?

PHP
大话西游666 2023-07-30 11:15:06
我正在创建一个 Laravel 电子商务网站,并使用 Voyager 作为后端。我在创建网站的&ldquo;订单&rdquo;部分时遇到了问题。我正在覆盖订单表的 voyager 视图&ldquo;read.blade.php&rdquo;。我还将我的 BREAD 链接到一个名为 OrdersController.php 的控制器。该文件如下(我添加的附加代码如下):<?phpnamespace App\Http\Controllers\Voyager;use App\Order;use Validator;use App\iamlush;use Illuminate\Http\Request;use TCG\Voyager\Facades\Voyager;use TCG\Voyager\Events\BreadDataAdded;use TCG\Voyager\Events\BreadDataUpdated;use TCG\Voyager\Http\Controllers\VoyagerBaseController;class OrdersController extends VoyagerBaseController{    //***************************************    //                _____    //               |  __ \    //               | |__) |    //               |  _  /    //               | | \ \    //               |_|  \_\    //    //  Read an item of our Data Type B(R)EAD    //    //****************************************    public function show(Request $request, $id)    {        $slug = $this->getSlug($request);        $dataType = Voyager::model('DataType')->where('slug', '=', $slug)->first();        $isSoftDeleted = false;        if (strlen($dataType->model_name) != 0) {            $model = app($dataType->model_name);            // Use withTrashed() if model uses SoftDeletes and if toggle is selected            if ($model && in_array(SoftDeletes::class, class_uses_recursive($model))) {                $model = $model->withTrashed();            }            if ($dataType->scope && $dataType->scope != '' && method_exists($model, 'scope'.ucfirst($dataType->scope))) {                $model = $model->{$dataType->scope}();            }            $dataTypeContent = call_user_func([$model, 'findOrFail'], $id);            if ($dataTypeContent->deleted_at) {                $isSoftDeleted = true;            }
查看完整描述

2 回答

?
茅侃侃

TA贡献1842条经验 获得超21个赞

错误提示找不到表。您需要通过在终端或命令行中输入来迁移表php artisan migrate



查看完整回答
反对 回复 2023-07-30
?
慕勒3428872

TA贡献1848条经验 获得超6个赞

您可以在控制器顶部添加:

Use DB;

当我需要获取或更改数据时,我总是需要使用它。


查看完整回答
反对 回复 2023-07-30
  • 2 回答
  • 0 关注
  • 91 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信