无法声明 class,因为该名称已在(同一文件)中使用

Cannot declare class because the name is already in use in (same file)

我在 运行 我的网络应用程序中遇到以下错误:

[Fri Jan 15 19:25:23 2021] PHP Fatal error:  Cannot declare class App\Http\Livewire\Customer because the name is already in use in /home/<username>/Projects/<project_name>/app/Http/Livewire/Customer.php on line 9

声明错误基本上是在抱怨它自己的文件,我不确定为什么。 这是 Customer.php 文件的内容:

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use Livewire\WithPagination;
use App\Models\Customer;
use Illuminate\Support\Facades\Auth;

class Customer extends Component
{
    use WithPagination;
    
    public function render()
    {
        $customers = Customer::where('user_id', Auth::id())->paginate(9);
        return view('livewire.customer')->with(['customers' => $customers]);
    }
}

谁能帮我解决这个问题?

要解决冲突,只需使用

use App\Models\Customer as AppCustomer;

那么您的 class 可以使用 AppCustomer 而不是 Customer

$customers = AppCustomer::where('user_id', Auth::id())->paginate(9);