PHP code example of emadha / eloquent-views

1. Go to this page and download the library: Download emadha/eloquent-views library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

emadha / eloquent-views example snippets



return [
    /**
     * The root directory of Eloquent views path in resources
     * by default it's using /resources/eloquent/{model name}
     */
    'path' => 'eloquent',
];

...
class Post extends Model {
   use \EmadHa\EloquentViews\HasEloquentViews;
   ...
}


# Render a single model view
Post::first()->render('block'); // Single block, rendered.

# Build views for a colletion of models
# This will return a collection object.
Post::all()->render('block');

# You can use 'implode' to get this as a single html string e.g. ...->implode(null);
Post::all()->render('block')->implode(null);
 bash
php artisan vendor:publish --provider="EmadHa\EloquentViews\ServiceProvider" --tag="config"
blade
<!-- /resources/views/eloquent/post/block.blade.php -->
<h1> {{ $model->title }} </h1>
<p> {{ $moredata }} </p>
blade
<!-- welcome.blade.php -->

<div class="news-items">
   {!! App\NewsItem::all()->render('block')->implode(null) !!}
</div>