Giter VIP home page Giter VIP logo

laravel-db-blade-compiler's Introduction

DB Blade Compiler

Render Blade templates from Eloquent Model Fields

This package generates and returns a compiled view from a blade-syntax field in your Eloquent model.

Installation (Laravel v < 5)

Require this package in your composer.json and run composer update (or run composer require flynsarmy/db-blade-compiler:1.* directly):

"flynsarmy/db-blade-compiler": "1.*"

After updating composer, add the ServiceProvider to the providers array in app/config/app.php

'Flynsarmy\DbBladeCompiler\DbBladeCompilerServiceProvider',

and the Facade to the aliases array in the same file

'DbView'          => 'Flynsarmy\DbBladeCompiler\Facades\DbView',

You can also optionally publish the config-file

php artisan config:publish flynsarmy/db-blade-compiler

Installation (Laravel 5.x)

Require this package in your composer.json and run composer update (or run composer require flynsarmy/db-blade-compiler:2.* directly):

"flynsarmy/db-blade-compiler": "2.*"

After updating composer, add the ServiceProvider to the providers array in app/config/app.php

'Flynsarmy\DbBladeCompiler\DbBladeCompilerServiceProvider',

and the Facade to the aliases array in the same file

'DbView'          => 'Flynsarmy\DbBladeCompiler\Facades\DbView',

You have to also publish the config-file

php artisan vendor:publish

Usage

This package offers a DbView facade with the same syntax as View but accepts a Model instance instead of path to view.

$template = Template::first();
return DbView::make($template)->with(['foo' => 'Bar'])->render();

Because you're passing a model to DbView::make(), db-blade-compiler needs to know which field to compile. By default this is content however you can set the field used with either of the following methods:

return DbView::make($template, ['foo' => 'Bar'], [], 'excerpt')->render();
return DbView::make($template)->field('excerpt')->with(['foo' => 'Bar'])->render();

You may set the default column used in the package config. You can enable using cache in compiling view from a blade-syntax field in your Eloquent model operation by enabling cache config in package config. By default this option is disabled.

License

db-blade-compiler is open-sourced software licensed under the MIT license

laravel-db-blade-compiler's People

Contributors

ebrahimradi avatar flynsarmy avatar hamway avatar rozklad avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.