vendredi 6 septembre 2019

Reuse Laravel model instance as fresh in foreach loop

I am having one question regarding laravel eloquent. I want to apply many queries inside foreach on eagerly loaded Laravel model

for example see below code

 $importedData = DataImportRecord::select('new_id');
foreach ($responses as $response) {
    //Here I want somthing that use fresh $importedData (from first line) for next itrestion
    $vehicle_brand_id = $importedData->where(['remarks'=>'xyz','some_id'=>$response['some_id']])->first();
    echo $vehicle_brand_id['new_id']." ==== ". $response['id']."\n"; //will work only oncee
}

as you see I can get new_id only once. I want that in each ittration I can use initial model so that in every hit from inside loop return updated new_id.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire