Download the PHP package emadha/eloquent-views without Composer
On this page you can find all versions of the php package emadha/eloquent-views. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download emadha/eloquent-views
More information about emadha/eloquent-views
Files in emadha/eloquent-views
Package eloquent-views
Short Description A Laravel Composer Package which attaches views to Eloquent Models, making it easier to render models views
License MIT
Informations about the package eloquent-views
Laravel Eloquent Views
A Composer Package to attach a render method to eloquent models.
I find it easier to render models views using a single line of code like model->render('view');
instead of going to controller, or having it inside a @include
in blade, or by using multiple lines of code to achieve that.
With this package, you can easily do so.
Requirements
This package requires Laravel 5.8 or higher, PHP 7.2 or higher.
Installation
You can install the package via composer:
The package will automatically register itself.
You can publish the config with:
The config file has the root diretory of the eloquent views
Usage
Adding HasEloquentViews
trait to your eloquent models is all you need to start using this package.
The views directory structure is like this: resources/views/eloquent/{model}/{view}
where eloquent is defined in the config file and model is your lowercase model class e.g. post
and the view is the view you request to render.
Example:
This code will look into /resources/views/eloquent/post/block.blade.php
and render it.
- The Data will be passed to the view through
$model
variable. - You can pass an array in the
render
method after the first argumentPost::first()->render('block', ['moredata'=>'Yes!]);
You can access that data like how you normally would, from a view:
The Beauty of it
How about you use this instead of including or creating the same code all the time ?
And not just that, imagine if you want to have the rendered view output in your controller, for example and api, or search controller, where you want to get the output? This will make this side of project as simple as it can be!