Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将数据从控制器共享到部分页脚_Php_Laravel_Laravel 5_Laravel 5.3 - Fatal编程技术网

Php 将数据从控制器共享到部分页脚

Php 将数据从控制器共享到部分页脚,php,laravel,laravel-5,laravel-5.3,Php,Laravel,Laravel 5,Laravel 5.3,在我的应用程序中,我将视图中的文件夹划分为: "posts" "pages" "partials" layout.blade.php 在我的文件夹partials中有刀片文件,如nav.blade.php和footer.blade.php。在我的文件夹“pages”中,有home.blade.php等文件和一些其他内部页面。 但现在我需要将一个可行的从控制器传递到我的页脚,因为它需要在所有视图中共享。 如何从页脚“pages”文件夹中管理刀片文件的PagesController传递变量 示例路

在我的应用程序中,我将视图中的文件夹划分为:

"posts"
"pages"
"partials"
layout.blade.php
在我的文件夹partials中有刀片文件,如nav.blade.php和footer.blade.php。在我的文件夹“pages”中,有home.blade.php等文件和一些其他内部页面。 但现在我需要将一个可行的从控制器传递到我的页脚,因为它需要在所有视图中共享。 如何从页脚“pages”文件夹中管理刀片文件的PagesController传递变量

示例路线:

Route::get('/', 'PageController@getHome');
Route::get('/registar', 'AuthenticationController@getRegistration');
Route::post('/post/comment', 'CommentController@store');
Route::get('/login', 'AuthenticationController@getLogin');

如果我理解正确,您想在每次调用特定视图时共享一些数据吗?如果是这样,您可以执行以下操作:

/* App\Providers\AppServiceProvider.php
** Edit the boot function, (dont forget to include View facade) */

public function boot(){
   View::composer('path_to_view', function($view)
    {
        $view->with('variable', $variable); // you can pass array here aswell
    });
}
另一种方法是(如果从正在访问的视图扩展页脚布局),在扩展布局时传递数据,如下所示:

@extends('footer', ['data' => $data])

如果需要从提供程序在multipe视图中共享同一变量。你也可以试试这个

public function boot()
{
        //set view path in array
        View::composer(['path_to_view1', 'path_to_view2'], function ($view) {
            $view->with('variableName', $variableName);
        });

}