Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

smeunus's avatar
Level 12

What is the best way to send multiple http request on a sequence?

I'll have to send some requests after a model is created.

I'm using a model observer for this.

I will send 4 - 6 request on some other endpoints. And all of them are different.

If one request fails, the next one will not execute. I feel like I'm into a trap.

public function created(Model $model){
    $response1 = Http::withHeaders($headers)->post();

    if($response1->ok){
        $response2 = sendAnother();
    }
}

public function sendAnother(){
    return Http::withHeaders($headers)->post();
}

Is there any better way to do this. Again I'll have to send 4 - 6 delete requests when a model is deleted. Please show me some lights.

0 likes
6 replies
EzekielGavin's avatar

Hi All,

I am currently in the process of hosting a Laravel app that has functionalities from Vue and Blade for the frontend.

While I was able to host the application on Google App Engine along with creating a build process (I still have to set up the database), I found the whole process to be very tedious due to my lack of experience with hosting such apps on Google App Engine. Therefore, does anyone know of the cleanest method to host an app on Google App Engine?

Thank you in advance. https://19216801.onl/ https://routerlogin.uno/ https://192168ll.link/

Snapey's avatar

Do you want them to all work? what should happen if one fails?

1 like
Sti3bas's avatar

@smeunus you can use Pipeline class:

$actions = [
   function ($model) {
      return Http::delete('https://test1.com/' . $model->id);
   },
   function ($model) {
      return Http::delete('https://test2.com/' . $model->id);
   },
   //...
];

app(Pipeline::class)
   ->send($model)
   ->through(collect($actions)->map(function ($action) {
         return function ($model, $next) use ($action) {
            $response = $action($model);

            // comment this condition if you don't want to stop further requests when one of the requests fails
            if (!$response->ok()) {
               return;
            }

            return $next($model);
         };
   })->all())
   ->thenReturn();

https://github.com/laravel/framework/blob/7.x/src/Illuminate/Pipeline/Pipeline.php

1 like
smeunus's avatar
Level 12

@snapey No. I want them to work if possible. If something went wrong then I'll handle it.

smeunus's avatar
Level 12

Holy Smoke!! @sti3bas I must try this. And I'll let you know. Huge thanks.

Please or to participate in this conversation.