# Pass Eloquent Model from Middleware to Action

**URL:** https://discourse.slimframework.com/t/pass-eloquent-model-from-middleware-to-action/4189
**Category:** Questions
**Created:** [May 24, 2020, 5:30pm UTC](https://discourse.slimframework.com/t/pass-eloquent-model-from-middleware-to-action/4189 "2020-05-24T17:30:51Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![PeterK](https://avatars.discourse-cdn.com/v4/letter/p/7993a0/32.png) [@PeterK](https://discourse.slimframework.com/u/PeterK)
#### Post date: [May 24, 2020, 5:30pm UTC](https://discourse.slimframework.com/t/pass-eloquent-model-from-middleware-to-action/4189/1 "2020-05-24T17:30:52Z")

</div>

Hi

I created my own OAuth Middleware and got a question about using it with Slim-Skeleton.

I got 2 layers of middleware.

First - Checks Token and validate it. When it is ok, I add it to request as an attribute.  
Second - Check if the User email is registered:

User::where(‘email’, $data[‘email’])-\>firstOrFail();

Now when I got the User model I add it again to request attribute.

Next I got my routes Actions that Extend the main Action in which I take the User Model out of the request and put it in the main protected variable in MainAction.

And here is my question.

Cause I can have my all DB functionality inside User model like take all orders like this:

return $this-\>respondWithData($this-\>user-\>orders()-\>get()-\>toArray());

So do I need Repositories at all if my data logic is like this??

Is it ok and save to have it like that ??

Do I break some big workflow patterns?

Everything is working nicely but it turns out I’m removing quiet a big amount of code and functionality from Slim Skeleton and I’m worried that I’m taking to much.

Is there a better way to pass it from Middleware to Action

Any suggestions and thoughts about this approach ??

Regards  
Peter
