ÿØÿà JFIF ÿþ; %PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
Server IP : 157.90.209.209 / Your IP : 216.73.216.129 [ Web Server : Apache System : Linux hcomm124.dns-wk.info 4.18.0-553.64.1.el8_10.x86_64 #1 SMP Mon Jul 28 12:01:56 EDT 2025 x86_64 User : evidenciarevista ( 1049) PHP Version : 7.2.34 Disable Function : exec,passthru,shell_exec,system Domains : 216 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/evidenciarevista/admin/vendor/laracasts/presenter/ |
Upload File : |
# Easy View Presenters So you have those scenarios where a bit of logic needs to be performed before some data (likely from your entity) is displayed from the view. - Should that logic be hard-coded into the view? **No**. - Should we instead store the logic in the model? **No again!** Instead, leverage view presenters. That's what they're for! This package provides one such implementation. ## Install Pull this package in through Composer. ```js { "require": { "laracasts/presenter": "0.1.*" } } ``` ## Usage The first step is to store your presenters somewhere - anywhere. These will be simple objects that do nothing more than format data, as required. Here's an example of a presenter. ```php use Laracasts\Presenter\Presenter; class UserPresenter extends Presenter { public function fullName() { return $this->first . ' ' . $this->last; } public function accountAge() { return $this->created_at->diffForHumans(); } } ``` Next, on your entity, pull in the `Laracasts\Presenter\PresentableTrait` trait, which will automatically instantiate your presenter class. Here's an example - maybe a Laravel `User` model. ```php <?php use Laracasts\Presenter\PresentableTrait; class User extends \Eloquent { use PresentableTrait; protected $presenter = 'UserPresenter'; } ``` That's it! You're done. Now, within your view, you can do: ```php <h1>Hello, {{ $user->present()->fullName }}</h1> ``` Notice how the call to the `present()` method (which will return your new or cached presenter object) also provides the benefit of making it perfectly clear where you must go, should you need to modify how a full name is displayed on the page. Have fun! Jeffrey @ [https://laracasts.com](https://laracasts.com)