1

I am trying to do something I've never done before in Laravel and cannot figure out how to do it. I have the following code in my Controller:

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'));

}

I am trying to accomplish the following:

  1. Get the application for a drug - this part of my code works
  2. Return an array of objects for the products (i.e. 7 products that belong to one application). I can do this but get stuck going to the next part.
  3. Next, I have to use the array of objects and search a table with the following columns: MarketingStatusID, ApplNo, ProductNo. I know how to query this table and get one row, but the problem is I have an array that I need to search. I imagine I have to use a loop but don't know where.
  4. Finally, I use the MarketingStatusID to retrieve the MarketingStatusDescription which I will know how to do.

I am also getting an error message that says:

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

In my Controller, I have use App\PharmaMarketingStatusLookup; so I am not sure why it is searching the Controllers folder

2 Answers 2

1

You have a typo in your class

From PharmaMarketingSatusLookup change to PharmaMarketingStatusLookup

App\Http\Controllers\profiles\PharmaMarketingStatusLookup
Sign up to request clarification or add additional context in comments.

1 Comment

I read 6 times to see the typo ... satus instead status...@Poldo
0

USE whereIn

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'));

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.