dongshui9690 2017-07-10 14:01
浏览 49

laravel在渲染之前将参数传递给主布局?

i am making an application and i want that pass error parameters to master view use within partial blade called error.blade.php.

i am checking some variable in controller and if anything occur error i added it to error array as below :

$error[] = 'error 1';

and i want to pass this to partial blade view called error.blade.php and render it but how can i do this ?

this array could be empty or not.

how can i pass this array to master layout before render ?

i use this error array every controller.

please help me

  • 写回答

2条回答 默认 最新

  • dqj29136 2017-07-10 14:28
    关注

    You can use a View Composer and just pass the data in within the boot() method of the provider.

        View::composer('master', function ($view) {
           $view->with('errors', $errors);          
        });
    

    The $errors will be available in your view now.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog