我已经花了几个小时在这上面,但无法克服这个错误,它突出显示了vendorapp.blade.php文件中的“@foreach($vendors as $vendor)”行。
登录(微风)工作正常,我可以输入用户凭据,所以我知道数据库工作正常。不知何故,尽管供应商刀片似乎不使用供应商应用控制器。当我将vendorapp.blade.php文件更改为仅显示$vendoritems时,它给出了相同的错误(未定义变量$vendoritems)。 为了还测试刀片文件是否未使用控制器,我可以在控制器中输入任何垃圾(例如“哈哈”)而不会引发错误。
路由是web.php:
<?php
use Illuminate\Support\Facades\Route;
Route::view('/', 'welcome')
->middleware(['auth', 'verified'])
->name('welcome');
require __DIR__.'/auth.php';
welcome.php 文件如下:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Vendor</title>
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.bunny.net">
<link href="https://fonts.bunny.net/css?family=figtree:400,600&display=swap" rel="stylesheet" />
<!-- Styles -->
<script src="https://cdn.tailwindcss.com"></script>
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body class="antialiased font-sans">
@livewire('vendorapp')
</body>
</html>
vendorapp.php 控制器:
<?php
namespace App\Livewire;
use App\Models\VendorItem;
use App\Models\Vendor;
use Livewire\Component;
use App\Livewire\Actions\Logout;
use Livewire\WithPagination;
class VendorApp extends Component
{
use WithPagination;
public $perPage = 25;
public $search = '';
public $sortDirection = 'ASC';
public $sortColumn = 'price';
public $filter = [];
public $filterInStockSydney;
public $filterInStockOther;
private $vendoritems = [];
/**
* Log the current user out of the application.
*/
public function logout(Logout $logout): void
{
$logout();
$this->redirect('/', navigate: true);
}
public function doSort($column)
{
if($this->sortColumn == $column) {
if ($this->sortDirection == "ASC") {
$this->sortDirection = "DESC";
}else{
$this->sortDirection = "ASC";
}
}else{
$this->sortColumn = $column;
$this->sortDirection = "ASC";
}
}
//lifecycle hooks
// reset the page when there is an updated perpage field
public function updatedPerPage(){
$this->resetPage();
}
// reset when there is an updated search
public function updatedSearch(){
$this->resetPage();
}
public function render()
{
$vendoritems = VendorItem::search($this->search);
if (!empty($this->filterInStockSydney)) {
$vendoritems = $vendoritems->Where('in_stock_sydney',true);
}
if (!empty($this->filterInStockOther)) {
$vendoritems = $vendoritems->Where('in_stock_other',true);
}
return view('livewire.vendorapp',
[
'vendoritems' => $vendoritems->orderBy($this->sortColumn, $this->sortDirection)
->paginate($this->perPage),
'vendors' => Vendor::orderBy('vendor','ASC')->get()
]
);
}
}
还有vendorapp.blade.php刀片文件:
)
<div>
<section class="mt-10">
<div class="md:flex">
<div class="md:flex-shrink-0">
<div class="mx-auto max-w-screen-xl px-4 lg:px-12">
<div class="bg-white dark:bg-gray-800 overflow-hidden">
<div class="flex items-center justify-between d p-4">
<div class="flex">
<div x-data="{ tooltip: false }">
<div class="flex gap-10">
<div>
<input wire:model.live.debounce.300ms="search" type="text" class="bg-gray-50 border border-gray-300" placeholder="Search" required="">
</div>
<div>
Stock Sydney: <input wire:model.live="filterInStockSydney" type="checkbox" class="bg-gray-50 border border-gray-300" required="">
</div>
<div>
Stock Other: <input type="checkbox" wire:model.live="filterInStockOther" class="bg-gray-50 border border-gray-300" required="">
</div>
<div>
<!-- this section is a tool tip popup -->
<button x-on:click="tooltip = !tooltip">
File dates
</button>
<div x-show="tooltip" class="z-50 x-50 absolute bg-white border-graphite border-2 rounded p-4 mt-1">
@foreach ($vendors as $vendor)
<tr class="border-b dark:border-gray-700">
<td class="px-4 py-3">
{{$vendor->vendor}} {{$vendor->refreshed}}<br>
</td>
</tr>
@endforeach
</div>
</div>
<div>
<label>Per Page</label>
<select class="w-20" wire:model.live="perPage">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
</select>
</div>
<div>
<button wire:click="logout" class="w-full text-start">
<x-dropdown-link>
{{ __('Log Out') }}
</x-dropdown-link>
</button>
</div>
</div>
</div>
</div>
</div>
<div class="overflow-x-auto">
<table class="w-full text-sm text-left text-gray-500">
<thead class="text-xs text-gray-700 uppercase">
<tr>
<th wire:click="doSort('vendor')" class="px-4 py-3">
<x-sort-column :sortColumn="$sortColumn" :sortDirection="$sortDirection" columnName="vendor"/>
</th>
<th wire:click="doSort('item')" class="px-4 py-3">
<x-sort-column :sortColumn="$sortColumn" :sortDirection="$sortDirection" columnName="item"/>
</th>
<th wire:click="doSort('manufacturer')" class="px-4 py-3">
<x-sort-column :sortColumn="$sortColumn" :sortDirection="$sortDirection" columnName="manufacturer"/>
</th>
<th class="px-4 py-3">
Description
</th>
<th wire:click="doSort('price')" class="px-4 py-3">
<x-sort-column :sortColumn="$sortColumn" :sortDirection="$sortDirection" columnName="price"/>
</th>
<th class="px-4 py-3">
Stock Sydney
</th>
<th class="px-4 py-3">
Stock Other
</th>
<th class="px-4 py-3">
ETA Sydney
</th>
<th class="px-4 py-3">
ETA Other
</th>
</tr>
</thead>
<tbody>
@foreach ($vendoritems as $vendoritem)
<tr class="border-b dark:border-gray-700">
<td class="px-4 py-3">
{{$vendoritem->vendor}}
</td>
<td class="px-4 py-3">
{!!$vendoritem->item!!}
</td>
<td class="px-4 py-3">
{{$vendoritem->manufacturer}}
</td>
<td class="px-4 py-3">
{{$vendoritem->description}}
</td>
<td class="px-4 py-3">
{{$vendoritem->price}}
</td>
<td class="px-4 py-3">
{{$vendoritem->stock_sydney}}
</td>
<td class="px-4 py-3">
{{$vendoritem->stock_other}}
</td>
<td class="px-4 py-3">
{{$vendoritem->eta_sydney}}
</td>
<td class="px-4 py-3">
{{$vendoritem->eta_other}}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="py-4 px-3">
{{$vendoritems->links()}}
</div>
</div>
</div>
</div>
</div>
</section>
</div>
我查看了班级的首都并尝试了不同的选项,但没有成功。
任何帮助都会很棒!
请在 cpanel 中对每个块发表评论,并在您的页面加载时报告我们