1. Go to this page and download the library: Download padosoft/laravel-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/ */
padosoft / laravel-presenter example snippets
namespace App\Presenters;
use Laracodes\Presenter\Presenter;
class UserPresenter extends Presenter
{
public function fullName()
{
return $this->model->first_name . ' ' . $this->model->last_name;
}
public function accountAge()
{
return $this->model->created_at->diffForHumans();
}
...
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Laracodes\Presenter\Traits\Presentable;
class User extends Model
{
use Presentable;
protected $presenter = 'App\Presenters\UserPresenter';
...
}
// automatically calls the property in the model
<h1>Hello, {{ $user->present()->firstName }}</h1> // automatically convert to snake_case
<h1>Hello, {{ $user->present()->first_name }}</h1>
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.