Pass an fix to the find method of a laravel model

0

I have a statement that is responsible for obtaining the packages using an $ id and the find () method of the model:

$package = Package::find($array);
    $package->each(function($package)
    {
        $package->type;
        $package->days;
        $package->hotels;
    });

This works perfect, it returns the information of each id of the $ array.

The $ array contains the values [1,2,3 ....] so it returns the information of the packages with their respective id, for filter purposes, I would like to add a clause where, but when using the following method:

$package = Package::where('id' = $array)
                    ->where('starts_at', '<=', '2017-06-07');
    $package->each(function($package)
    {
        $package->type;
        $package->days;
        $package->hotels;
    });

He does not return anything to me ...

Does anyone know how each of the array ids could pass and get their respective data?

    
asked by Jesus 07.06.2017 в 23:16
source

1 answer

1

You still need to add the get () method to execute the query and correct the syntax of the first where, changing it to a whereIn to accept the array:

$package = Package::whereIn('id', $array)
    ->where('starts_at', '<=', '2017-06-07')
    ->get();
    
answered by 07.06.2017 / 23:36
source