# Route Groups -\> Each route to execute common code?

**URL:** <https://discourse.slimframework.com/t/route-groups-each-route-to-execute-common-code/2495>\
**Category:** Questions\
**Created:** [June 23, 2018, 5:08pm UTC](https://discourse.slimframework.com/t/route-groups-each-route-to-execute-common-code/2495 "2018-06-23T17:08:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcatlga](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@jcatlga](https://discourse.slimframework.com/u/jcatlga)\
**Post date:** [June 23, 2018, 5:08pm UTC](https://discourse.slimframework.com/t/route-groups-each-route-to-execute-common-code/2495/1 "2018-06-23T17:08:54Z")

</div>

I like the idea of route groups. Is it possible somehow in Slim that each route function in a group execute some common code at the start of each function?

Instead of having a copy of the code in each function, can the code be in one place, and all the routes execute that code?

Basically I want to add some extra security and if it fails return null. I don’t want to put that code in all the functions in the group.

Thanks.

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [June 24, 2018, 10:50am UTC](https://discourse.slimframework.com/t/route-groups-each-route-to-execute-common-code/2495/2 "2018-06-24T10:50:26Z")

</div>

Hi @jcatlga

I think a [Group Middleware](https://www.slimframework.com/docs/v3/concepts/middleware.html#group-middleware) is what you’re looking for.
