在控制器中返回对象数组后在Laravel中查找模型

在控制器中返回对象数组后在Laravel中查找模型,laravel,eloquent,Laravel,Eloquent,我正在尝试做一些我以前在拉雷维尔从未做过的事情,但我不知道如何去做。 我的控制器中有以下代码: public function show($id) { //Get application for drug $application = PharmaApplication::where('ApplNo', $id)->first(); //Get all products for given application (i.e. the different quan

我正在尝试做一些我以前在拉雷维尔从未做过的事情,但我不知道如何去做。 我的控制器中有以下代码:

public function show($id)
{
    //Get application for drug
    $application = PharmaApplication::where('ApplNo', $id)->first();


    //Get all products for given application (i.e. the different quantities and forms drug comes in)
    $product = PharmaProduct::where('ApplNo', $id)->get();

    foreach($product as $product){
            $product->ProductNo;
    }


    //Get Marketing Status for drug
    $marketingStatus = DB::table('pharma_marketing_statuses')
                            ->where('ApplNo', $id)
                            ->where('ProductNo', $product->ProductNo)
                            ->get();


    //Lookup marketing status Description
    $marketingStatusDescription = PharmaMarketingSatusLookup::where('MarketingStatusID', $marketingStatus->MarketingStatusID);

    return view('profiles.drug', compact('application', 'product', 'marketingStatus', 'marketingStatusDescription'));

}
我正在努力实现以下目标:

  • 获取药物的应用程序-我的这部分代码有效
  • 返回产品的对象数组(即属于一个应用程序的7个产品)。我可以做到这一点,但我无法进入下一部分
  • 接下来,我必须使用对象数组并搜索具有以下列的表:
    MarketingStatusID
    ApplNo
    ProductNo
    。我知道如何查询这个表并获得一行,但问题是我有一个需要搜索的数组。我想我必须使用一个循环,但不知道在哪里
  • 最后,我使用
    MarketingStatusID
    检索MarketingStatusDescription,我将知道如何进行检索
  • 我还收到一条错误消息,上面说:

    Class 'App\Http\Controllers\profiles\PharmaMarketingSatusLookup' not found
    

    在我的控制器中,我已使用App\PharmaMarketingStatusLookup;所以我不知道它为什么要搜索Controllers文件夹,你班上有个打字错误

    从PharmaMarketingSatusLookup更改为PharmaMarketingStatusLookup

    App\Http\Controllers\profiles\PharmaMarketingStatusLookup
    

    使用
    其中

    use App\PharmaApplication;
    use App\PharmaProduct;
    use App\PharmaMarketingSatusLookup;
    
    public function show($id)
    {
        $application = PharmaApplication::where('ApplNo', $id)->first();
    
        $products = PharmaProduct::where('ApplNo', $id)->get();
    
        $productid = array();
        foreach($products as $product){
               $productid[] = $product->ProductNo;
        }
    
    
        $marketingStatus = DB::table('pharma_marketing_statuses')
                                ->where('ApplNo', $id)
                                ->whereIn('ProductNo', $productid)
                                ->get();
    
    
        $marketingStatusDescription = PharmaMarketingSatusLookup::where('MarketingStatusID', $marketingStatus->MarketingStatusID);
    
        return view('profiles.drug', compact('application', 'product', 'marketingStatus', 'marketingStatusDescription'));
    
    }
    

    我读了6遍才看到打字错误。。。satus取而代之的是地位…@Poldo