PHP code example of coderflexx / laravel-presenter
1. Go to this page and download the library: Download coderflexx/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/ */
coderflexx / laravel-presenter example snippets
return [
/*
|--------------------------------------------------------------------------
| Presenter Namespace
|--------------------------------------------------------------------------
|
| This value informs LaravelPresenter which namespace you will be
| selecting to store your presenters by default.
| If this value equals to null, "App\Presenter" will be used
| by default.
|
*/
'presenter_namespace' => 'App\\Presenters',
];
use Coderflex\LaravelPresenter\Concerns\CanPresent;
use Coderflex\LaravelPresenter\Concerns\UsesPresenters;
// ...
class User extends Authenticatable implements CanPresent
{
use UsesPresenters;
// ...
}
namespace App\Presenters;
use Coderflex\LaravelPresenter\Presenter;
class UserPresenter extends Presenter
{
//
}
use App\Presenters\UserPresenter;
use Coderflex\LaravelPresenter\Concerns\CanPresent;
use Coderflex\LaravelPresenter\Concerns\UsesPresenters;
// ...
class User extends Authenticatable implements CanPresent
{
use UsesPresenters;
protected $presenters = [
'default' => UserPresenter,
];
}
...
class UserPresenter extends Presenter
{
public function fullName()
{
return "{$this->model->first_name} {$this->model->last_name}";
}
}
...
$user->present()->fullName
use App\Presenters\UserPresenter;
use Coderflex\LaravelPresenter\Concerns\CanPresent;
use Coderflex\LaravelPresenter\Concerns\UsesPresenters;
// ...
class User extends Authenticatable implements CanPresent
{
use UsesPresenters;
protected $presenters = [
'default' => UserPresenter,
'setting' => UserSettingPresenter,
];
}
...
class UserSettingPresenter extends Presenter
{
public function lang()
{
return $this->model->settings->defaultLang;
}
}
...