继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

ShareErrorsFromSession.php

ITMISS
关注TA
已关注
手记 385
粉丝 51
获赞 245

<?php

 

namespace Illuminate\View\Middleware;

 

use Closure;

use Illuminate\Support\ViewErrorBag;

use Illuminate\Contracts\View\Factory as ViewFactory;

 

class ShareErrorsFromSession

{

    /**

     * The view factory implementation.

     *

     * @var \Illuminate\Contracts\View\Factory

     */

    protected $view;// The view factory implementation

 

    /**

     * Create a new error binder instance.

     *

     * @param  \Illuminate\Contracts\View\Factory  $view

     * @return void

     */

    public function __construct(ViewFactory $view)

    {

        $this->view = $view;//set this view

    }//Create a new error binder instance.

 

    /**

     * Handle an incoming request.

     *

     * @param  \Illuminate\Http\Request  $request

     * @param  \Closure  $next

     * @return mixed

     */

    public function handle($request, Closure $next)

    {//Handle an incoming request.

        // If the current session has an "errors" variable bound to it, we will share

        // its value with all view instances so the views can easily access errors

        // without having to bind. An empty bag is set when there aren't errors.

        $this->view->share(

            'errors', $request->session()->get('errors') ?: new ViewErrorBag

        );//If the current session has an "errors" variable bound to it,we will share

       //its value with all view instances so the views can easily access errors

       //without having to bind. An empty bag is set when there aren't errors.

 

        // Putting the errors in the view for every view allows the developer to just

        // assume that some errors are always available, which is convenient since

        // they don't have to continually run checks for the presence of errors.

 

        return $next($request);

       //Putting the errors in the view for every view allows the developer to just

       // assume that some errors are always available, which is convenient since

       // they don't have to continually run checks for the presence of errors.

    }

}

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP