laravel 如何在 Jmeter 板页面中显示计数?

7eumitmz  于 2023-05-23  发布在  其他
关注(0)|答案(3)|浏览(121)

当我试图在 Jmeter 板页面中显示计数时出现未定义变量错误
我尝试在 Jmeter 板页面中显示工具数量的计数。但是,它显示错误:未定义变量$jumlahalat

web.php

Route::get('/dashboard-admin', function () {
    $jumlahalat = Inventory::count();
    return view('dashboard-admin', compact('jumlahalat'));
});

dashboard-admin.blade.php

<div class="grid grid-cols-4 gap-4 rounded mt-4 text-md font-bold text-[#fecbcf] w-full">
    <a href="{{ url('/sda/alat') }}" class="text-white" style="text-decoration: none; color: inherit;">
        <div class="bg-[#5479f7] flex gap-3 pl-5 justify-start items-center rounded-lg h-[110px]">
            <div class="h-[70px] w-[70px] rounded-sm bg-white flex justify-center items-center">
                <span class="material-icons text-black" style="font-size: 40px">inventory_2</span>
            </div>
            <div>
                <div class="self-center text-start">Jumlah Alat</div>
                <div class="self-center text-start">{{ $jumlahalat }}</div>
            </div>
        </div>
    </a>
</div>

我已经在web.php中定义了use App\Models\Inventory

chhqkbe1

chhqkbe11#

这也可能只是路由/视图缓存问题。尝试在项目上运行这些命令

php artisan route:clear

而且

php artisan view:clear
i7uq4tfw

i7uq4tfw2#

如果你试着在你的 Jmeter 板上做这个计数器。然后你可以尝试我的方式……在你的控制器上。你可以简单地返回你的所有模型…

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\ProductCategory;
use App\Models\Products;
use App\Models\Customer;

class PageController extends Controller
{
    public function dashboard()
    {
        $category = ProductCategory::all();
        $products = Products::all();
        $customer = Customer::all();
        return view('admin/dashboard',compact('category','products','customer'));
    }

}```

 and then you can call this on you page for count...

              ```<div class="card-body">
                <div class=" float-end fs-1 fw-bolder opacity-25">
                <i class="fa-solid fa-box"></i>
                    </div>
                    <h5 class="card-title text-center">Total Products</h5>
                    <p class="card-text fs-1 text-center fw-bolder">{{$products->count()}}</p>
                </div>```
9w11ddsr

9w11ddsr3#

确保导入了正确的Inventory模型类,通常它位于App\Models\Inventory
尝试更改$jumlahalat = Inventory::count()

Route::get('/dashboard-admin', function () {
    $jumlahalat = Inventory::count();
    return view('dashboard-admin', compact('jumlahalat')); });

$jumlahalat = Inventory::all()->count();

相关问题