-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Session is no longer available for service providers. Create a middle…
…ware
- Loading branch information
Showing
3 changed files
with
49 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Ghunti\LaravelBase\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Contracts\Routing\Middleware; | ||
use Illuminate\Support\MessageBag; | ||
use Illuminate\Contracts\View\Factory as ViewFactory; | ||
|
||
class ShareMessagesFromSession implements Middleware | ||
{ | ||
/* Create a new error binder instance. | ||
* | ||
* @param \Illuminate\Contracts\View\Factory $view | ||
* @return void | ||
*/ | ||
public function __construct(ViewFactory $view) | ||
{ | ||
$this->view = $view; | ||
} | ||
|
||
/** | ||
* Same logic provided by Illuminate\View\Middleware::ShareErrorsFromSession to bind | ||
* the messages from session to the view. | ||
* If 'messages' exist in the session, a variable $messages will be inserted into the view. | ||
* If no 'messages' exist on the session an empty MessageBag is inserted | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next) | ||
{ | ||
if ($request->session()->has('messages')) { | ||
$this->view->share('messages', $request->session()->get('messages')); | ||
} else { | ||
$this->view->share('messages', new MessageBag); | ||
} | ||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters