【问题标题】:How to add 50,000 Products in Laravel Database product table如何在 Laravel 数据库产品表中添加 50,000 个产品
【发布时间】:2020-11-18 10:48:03
【问题描述】:

我有一个包含 50,000 个产品的 MySQL 查询我从 SQL 查询中插入了 10 个产品,但它没有显示在管理面板中。

我是 laravel 新手

如何显示这个 laravel 模型 MySQL 查询

$productList = (new ShopProduct)
            ->leftJoin($tableDescription, $tableDescription . '.product_id', $tableProduct . '.id')
            ->where($tableProduct . '.store_id', session('adminStoreId'))
            ->where($tableDescription . '.lang', sc_get_locale());

【问题讨论】:

    标签: php mysql laravel eloquent


    【解决方案1】:

    您的控制器函数应如下所示:

    $products = Product::all(); // Fetch rows from Product Model
    return view('yourviewfilename', array('products' => $products)); // taking products object to your view file
    

    你需要如何在视图文件上显示:

    @foreach ($products as $item)
        <tr>
            <td>{{$item->id}}</td>
            <td>{{$item->name}}</td>
        </tr>
    @endforeach
    

    【讨论】:

    • 如何在模型中回显 mysql 查询,如“select *....”
    • $results = \DB::select("SELECT * FROM users"); 通过这种方式你可以在 Laravel 中使用自定义查询
    • 在任何代码中显示上述代码的查询(我写在我的问题中)
    • 您在寻找查询日志吗???意味着您正在寻找生成的查询...对吗????
    • 是的,我正在寻找查询日志。我可以在哪里看到查询日志
    【解决方案2】:

    首先你必须启用查询日志,它可以使用

    DB::connection()->enableQueryLog();
    

    那么你可以使用下面的代码来查看查询日志

    $queries = DB::getQueryLog();
    

    如果你想查看最后执行的查询

    $last_query = end($queries);
    

    要了解有关日志记录的更多信息,请参阅https://laravel.com/docs/5.0/database#query-logging

    例子

    public function show(Order $order){
            \DB::connection()->enableQueryLog();
            $data = $order->all();
            $queries = \DB::getQueryLog();
            return dd($queries);
    }
    

    【讨论】:

      猜你喜欢
      • 2013-05-17
      • 1970-01-01
      • 1970-01-01
      • 2021-12-04
      • 1970-01-01
      • 2021-04-06
      • 2018-05-10
      • 2018-12-10
      • 1970-01-01
      相关资源
      最近更新 更多