Laravel收银员将为所有客户提供服务

Laravel收银员将为所有客户提供服务,laravel,laravel-cashier,Laravel,Laravel Cashier,我正在使用laravel收银员版本9和laravel 5.8,条带订阅已正确完成,每个用户都可以在用户仪表板页面上看到自己的发票 基本上,我们在我们的网站上使用两种类型的用户,一种是普通用户,另一种是管理员,在普通用户仪表板中,我们显示发票,并且使用下面的代码可以正常工作 public function index() { try { $invoices = Auth::user()->invoicesIncludingPending();

我正在使用laravel收银员版本9和laravel 5.8,条带订阅已正确完成,每个用户都可以在用户仪表板页面上看到自己的发票

基本上,我们在我们的网站上使用两种类型的用户,一种是普通用户,另一种是管理员,在普通用户仪表板中,我们显示发票,并且使用下面的代码可以正常工作

public function index()
    {
        try {
            $invoices = Auth::user()->invoicesIncludingPending();
        } catch ( \Exception $e ) {
            session()->flash('status', $e->getMessage());
        }

        return view('invoice', compact('invoices'));
    }

现在,我们希望在管理仪表板末端列出并显示所有用户的所有发票,以便管理员可以在管理仪表板中查看所有用户的所有发票数据。你能帮助我,我如何在管理仪表板中实现这一点。

我认为你已经完成了80%的工作,现在按照说明进行操作,因为我没有关于你的模型和关系的完整信息。这个答案只是假设

 public function socpeInvoice($query)
{
    //put this type of function in your invoice model
    //make a relation in your user model fro user Invoice like this the bleow commented function

   /*  public function invoice()
    {
        return $this->hasMany(Invoice::class, 'user', 'id');
    } */
    //check for the condition how you get the only pending invoice hear i have used status as pending. you can check in your condition,

    if(Auth::user() == 'Admin'){
        User::whereHas('invoice',function($query){
            $query->where('status','pending');
        })->orderBy('id','asc'); //check in your condition how you get the admin user
    }else{
        Auth::user()->invoicesIncludingPending();//you can call your function hear
    }
    //As i dont know the logic inside invoicesIncludingPending() function i can only help you out till this extent

}
这是基于假设的答案,因为我不知道您的模型和功能

在你的控制器上

public function index()
{
    try {
        $invoices = User::Invoice()->get();//or paginate
    } catch ( \Exception $e ) {
        session()->flash('status', $e->getMessage());
    }

    return view('invoice', compact('invoices'));
}