php - Using presenters in Laravel 5 -
php - Using presenters in Laravel 5 -
i've watched laracasts video presenters , want utilize them in project.
i have page display user activity log. in foreach loop display "activity" model. activity uses polymorphic relationship, depending on activity type need display different kind of content. example, user may send email, add together task, create something, delete etc.
depending on action should display different icons, different content (some activities may contain links, may contain else).
when watched , read examples of presenters, realize of them quite simple , uses such things ucfirst
or date-formatting. however, should set lot of html logic in presenters? example, since have different icon different actions set big switch returns <i>
tag appropriate icon class. then, when displaying description of action switch , homecoming html, links, <audio>
tag.
also not convenient utilize html in presenters, @ same time want maintain view clean, can output $activity->presenter()->description
instead of lot of @if
operators.
an illustration of presenter method:
public function icon() { switch ($this->entity->type->name) { case 'call': homecoming '<i class="fa fa-phone activity-call-icon"></i>'; case 'visit': homecoming '<i class="fa fa-car activity-visit-icon"></i>'; case 'email': homecoming '<i class="fa fa-send activity-email-icon"></i>'; case 'note': homecoming '<i class="fa fa-pencil activity-task-icon"></i>'; case 'create_checkin': homecoming '<i class="flaticon-pin56"></i>'; default: homecoming '<i class="fa fa-dot-circle-o"></i>'; } }
php laravel laravel-5 presenter
Comments
Post a Comment