# Best way to exit after response / flow control

**URL:** <https://discourse.slimframework.com/t/best-way-to-exit-after-response-flow-control/3051>\
**Category:** Questions\
**Created:** [March 21, 2019, 4:42pm UTC](https://discourse.slimframework.com/t/best-way-to-exit-after-response-flow-control/3051 "2019-03-21T16:42:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![andiG](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@andiG](https://discourse.slimframework.com/u/andiG)\
**Post date:** [March 21, 2019, 4:42pm UTC](https://discourse.slimframework.com/t/best-way-to-exit-after-response-flow-control/3051/1 "2019-03-21T16:42:25Z")

</div>

Dear Slim Team

Let’s assume a simple route like this:

```
$app->post('/ticket/new', function (Request $request, Response $response) use ($cfgAPI) {
    doing stuff here

   $response->getBody()->write("we are done");
   return $response;
});

```

If I put in some conditional logic inside this route - what is the best practice to exit if some condition is reached?

simple condition  
if ($a == “yes”) {  
$response-\>getBody()-\>write(“done case yes”);  
return $response;  
} else {  
$response-\>getBody()-\>write(“done case no”);  
return $response;  
}

But if I have more complex conditions, the following way would be nice - but is this allowed/supported? I saw halt/stop is removed in V3:

```
if ($a == "yes") {
   $response->getBody()->write("done case yes");
   return $response;
   AND DO NOT PROCESS FURTHER exit/halt/stop here
}

```

…and more logic…  
…and more logic…

Sorry, but I can’t find this in the docs.  
Thanks for helping out!  
andi

---

<div class="post-metadata">

**Author:** ![tflight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/tflight/32/1205_2.png) [@tflight](https://discourse.slimframework.com/u/tflight)\
**Post date:** [March 21, 2019, 7:16pm UTC](https://discourse.slimframework.com/t/best-way-to-exit-after-response-flow-control/3051/2 "2019-03-21T19:16:14Z")

</div>

> [@andiG](#):
>
> But if I have more complex conditions, the following way would be nice - but is this allowed/supported?

Yes, that is indeed what will happen. I use it fairly often and I believe the technique is called “early return”. Once you `return` the `$response` you’re done. Slim will process any remaining middleware, etc, but so far as that action is concerned nothing further gets processed.

---

<div class="post-metadata">

**Author:** ![andiG](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@andiG](https://discourse.slimframework.com/u/andiG)\
**Post date:** [March 21, 2019, 7:21pm UTC](https://discourse.slimframework.com/t/best-way-to-exit-after-response-flow-control/3051/3 "2019-03-21T19:21:04Z")

</div>

I see, an option would be great to have no middleware processed further as well.

…but I can work around this.  
Thanks.

---

<div class="post-metadata">

**Author:** ![aghezzi](https://avatars.discourse-cdn.com/v4/letter/a/7993a0/32.png) [@aghezzi](https://discourse.slimframework.com/u/aghezzi)\
**Post date:** [March 25, 2019, 9:36am UTC](https://discourse.slimframework.com/t/best-way-to-exit-after-response-flow-control/3051/4 "2019-03-25T09:36:42Z")

</div>

If you don’t setup any middleware no further processing Take Place
