According to Laravel 4 documentation.

Composer is:

View composers are callbacks or class methods that are called when a view is rendered. If you have data that you want bound to a given view each time that view is rendered throughout your application, a view composer can organize that code into a single location. Therefore, view composers may function like "view models" or "presenters".

View::composer('profile', function($view)
{
    $view->with('count', User::count());
});

And

Creator is:

视图创建者的工作方式几乎与视图生成器完全相同;然而,当视图被实例化时,它们会立即被激发.要注册视图创建者,只需使用creator方法

View::creator('profile', function($view)
{
    $view->with('count', User::count());
});

所以问题是:What is the difference?

推荐答案

When you use View::creator you have the chance to override the variables of view in the controller. Like this:

View::creator('layout', function($view) {
    $view->with('foo', 'bar');
});

// in controller
return View::make('layout')->with('foo', 'not bar at all');

// it's defined as 'not bar at all' in the view

-

View::composer('hello', function($view) {
    $view->with('foo', 'bar');
});

// in controller
return View::make('hello')->with('foo', 'not bar at all');

// it's defined as 'bar' in the view

Laravel相关问答推荐

@vite指令在使用laravel vite构建后导致错误

如何解决此 Backblaze B2 S3 兼容 API 错误?

Inertiajs - 使用链接组件添加记录但无法在不使用表单的情况下清除文本区域

如何自定义密码确认不匹配.错误信息?

如何在生产中的 laravel 应用程序中获取标头请求值?

如何通过单击进入 vs 代码中的类

找不到 Laravel 5 类日志(log)

Laravel Eloquent - 随叫随到的加密/解密数据

在laravel中将数据插入数据透视表

Laravel 5 - 仅在特定页面/控制器(页面特定assets资源)上添加样式表

如何在使用 Laravel 在控制器中发送邮件之前更改邮件配置?

laravel 5中的配置缓存导致找不到视图

Homestead:文件夹映射到错误的文档根目录

Laravel 4 - 如何将所有字段的所有验证错误消息作为 JSON struct 返回?

Filesystem.php 中的 ErrorException

Laravel Eloquent 多态一对一?

无法声明类 Controller,因为该名称已在使用中

Laravel 在域和子域中共享 cookie 检测问题

如何使 Laravel (Blade) 文本字段只读

将图像保存在公共文件夹中,而不是存储 laravel 5