taylornetwork / row-col-renderer
Requires
- php: >=7.1
- illuminate/support: >=5.5
Requires (Dev)
- orchestra/testbench: ^3.8
This package is auto-updated.
Last update: 2024-11-18 10:28:13 UTC
README
This package dynamically renders Bootstrap rows and cols depending on the number of items a model has.
You can set a maximum per row
Examples:
Install
$ composer require taylornetwork/row-col-renderer
Usage
To generate a new Renderer run
$ php artisan make:renderer ModelName
Where ModelName
is the name of the model you want to use for this renderer.
This would generate a App\Renderers\ModelNameRenderer
class
use Illuminate\Database\Eloquent\Model; use TaylorNetwork\RowColRenderer\Renderer; class ModelNameRenderer extends Renderer { protected $model = \App\ModelName::class; public function getView(Model $item): string { return view('someview', ['someModel' => $item]); } }
To use all you need is to create a view or string to output the item data.
Example
Let's say you have a landing page that you want to display some of the services you offer to clients.
You have a model App\Service
You would create a view resources/views/partials/service.blade.php
<div class="col-md"> <span class="fa-stack fa-4x"> <i class="fas fa-circle fa-stack-2x text-primary"></i> <i class="fas fa-{{ $service->icon }} fa-stack-1x fa-inverse"></i> </span> <h4 class="service-heading">{{ $service->title }}</h4> </div>
Run the artisan command
$ php artisan make:renderer Service
In your app/Renderers/ServiceRenderer.php
use Illuminate\Database\Eloquent\Model; use TaylorNetwork\RowColRenderer\Renderer; class ServiceRenderer extends Renderer { protected $model = \App\Service::class; public function getView(Model $item): string { return view('partials.service', ['service' => $item]); } }
Then where ever you want to render the services:
{!! Renderer::service()->render() !!}
9 Services
8 Services
7 Services