| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Illuminate\View\Middleware;
|
|
|
4 |
|
|
|
5 |
use Closure;
|
|
|
6 |
use Illuminate\Contracts\View\Factory as ViewFactory;
|
|
|
7 |
use Illuminate\Support\ViewErrorBag;
|
|
|
8 |
|
|
|
9 |
class ShareErrorsFromSession
|
|
|
10 |
{
|
|
|
11 |
/**
|
|
|
12 |
* The view factory implementation.
|
|
|
13 |
*
|
|
|
14 |
* @var \Illuminate\Contracts\View\Factory
|
|
|
15 |
*/
|
|
|
16 |
protected $view;
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* Create a new error binder instance.
|
|
|
20 |
*
|
|
|
21 |
* @param \Illuminate\Contracts\View\Factory $view
|
|
|
22 |
* @return void
|
|
|
23 |
*/
|
|
|
24 |
public function __construct(ViewFactory $view)
|
|
|
25 |
{
|
|
|
26 |
$this->view = $view;
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Handle an incoming request.
|
|
|
31 |
*
|
|
|
32 |
* @param \Illuminate\Http\Request $request
|
|
|
33 |
* @param \Closure $next
|
|
|
34 |
* @return mixed
|
|
|
35 |
*/
|
|
|
36 |
public function handle($request, Closure $next)
|
|
|
37 |
{
|
|
|
38 |
// If the current session has an "errors" variable bound to it, we will share
|
|
|
39 |
// its value with all view instances so the views can easily access errors
|
|
|
40 |
// without having to bind. An empty bag is set when there aren't errors.
|
|
|
41 |
$this->view->share(
|
|
|
42 |
'errors', $request->session()->get('errors') ?: new ViewErrorBag
|
|
|
43 |
);
|
|
|
44 |
|
|
|
45 |
// Putting the errors in the view for every view allows the developer to just
|
|
|
46 |
// assume that some errors are always available, which is convenient since
|
|
|
47 |
// they don't have to continually run checks for the presence of errors.
|
|
|
48 |
|
|
|
49 |
return $next($request);
|
|
|
50 |
}
|
|
|
51 |
}
|