Download the PHP package dunice/laravel-view-components without Composer
On this page you can find all versions of the php package dunice/laravel-view-components. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dunice/laravel-view-components
More information about dunice/laravel-view-components
Files in dunice/laravel-view-components
Package laravel-view-components
Short Description A better way to connect data with view rendering in Laravel
License MIT
Homepage https://github.com/spatie/laravel-view-components
Informations about the package laravel-view-components
THIS PACKAGE HAS BEEN ABANDONED
A better way to connect data with view rendering in Laravel
View components are a way to help organize logic tied to view, similar to view composers.
A view component can be anything that implements Laravel's Htmlable
contract, so you don't necessarily need to use Blade views to render the component. This is useful for wrapping third party HTML packages, like spatie/laravel-menu.
The benefit over view composers is that data and rendering logic are explicitly tied together in components instead of being connected afterwards. They also allow you to seamlessly combine properties and dependency injection.
This package is based on Introducing View Components in Laravel, an alternative to View Composers by Jeff Ochoa.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
No additional setup necessary. Laravel will automatically discover and register the service provider.
Optionally you can publish the config file with:
This is the default content of the file that will be published at config/view-components
:
Usage
The @render
directive
The @render
Blade directive accepts two arguments: the first is the view component's path or class name, the second is an extra set of properties (optional).
You can choose between referencing the component via a path or a class name.
Parameters will be injected in the view components __construct
method. The component is instantiated with Laravel's container, so parameters that aren't provided by render will be automatically injected.
In the above example, $color
is explicitly set, and a $request
object will be injected by Laravel.
Configuration
The root namespace
By configuring root_namespace
, you can define where the bulk of your view components are located. By default, this is in App\Http\ViewComponents
.
The above components can be rendered with @render('myComponent')
and @render('nested.nestedComponent')
.
Additional namespaces
You can register additional namespaces in the namespaces
configuration, similar to view paths.
The above Menu
component can now be rendered with @render('navigation::menu')
.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Sebastian De Deyne
- All Contributors
License
The MIT License (MIT). Please see License File for more information.