PHP code example of lewis / presenter

1. Go to this page and download the library: Download lewis/presenter 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/ */

    

lewis / presenter example snippets


'providers' => [
    Lewis\Presenter\PresenterServiceProvider::class
]

return [

    App\User::class => App\Presenters\UserPresenter::class,
    App\Post::class => App\Presenters\PostPresenter::class

];

$this->app['decorator']->setBindings([
    \App\User::class => \App\Presenters\UserPresenter::class,
    \App\Post::class => \App\Presenters\PostPresenter::class
]);

$this->app['decorator']->register(\App\User::class, \App\Presenters\UserPresenter::class);

namespace App\Presenters;

use Lewis\Presenter\AbstractPresenter;

class UserPresenter extends AbstractPresenter
{

}

namespace App\Presenters;

use App\SomeNamespace\SomeClass;
use Lewis\Presenter\AbstractPresenter;

class UserPresenter extends AbstractPresenter
{
    protected $class;

    public function __construct($object, SomeClass $class)
    {
        $this->class = $class;

        parent::__construct($object);
    }
}

public function prettySlug()
{
    return '/'.ltrim($this->slug, '/');
}

public function prettySlug()
{
    return '/'.ltrim($this->object->slug, '/');
}

{{ $post->prettySlug }}

Or:

{{ $post->prettySlug() }}

{{ $post->title }}

@foreach($post->comments as $comment)
    ...
@endforeach

$ php artisan vendor:publish --provider="Lewis\Presenter\PresenterServiceProvider"