Skip to content

Commit a91a389

Browse files
committed
Add FlushEntityManager middleware.
1 parent 911a857 commit a91a389

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ php artisan make:doctrine:mapping MyValue --value
108108

109109
By default, this will create a new file in `app/Database/Doctrine/Mappings/Values/` called `MyValueMapping.php`.
110110

111+
### FlushEntityManager Middleware
112+
113+
Simplify the process of actually persisting your entities to the database using the included middleware.
114+
115+
Add the middleware to your `app/Http/Kernel.php` file like so:
116+
```php
117+
class Kernel extends HttpKernel
118+
{
119+
// ...
120+
121+
protected $middleware = [
122+
// ...
123+
\Zain\LaravelDoctrine\Jetpack\Middleware\FlushEntityManager::class,
124+
];
125+
}
126+
```
127+
111128
### Helpers
112129

113130
#### Entity Serialization

src/Middleware/FlushEntityManager.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Zain\LaravelDoctrine\Jetpack\Middleware;
4+
5+
use Closure;
6+
use Doctrine\ORM\EntityManagerInterface as EntityManager;
7+
use Illuminate\Http\Request;
8+
9+
class FlushEntityManager
10+
{
11+
private EntityManager $em;
12+
13+
public function __construct(EntityManager $em)
14+
{
15+
$this->em = $em;
16+
}
17+
18+
/**
19+
* @return mixed
20+
*/
21+
public function handle(Request $request, Closure $next)
22+
{
23+
$response = $next($request);
24+
25+
$this->em->flush();
26+
27+
return $response;
28+
}
29+
}

0 commit comments

Comments
 (0)