ImArtur
140
1
Laravel

Anti-pattern and more.. questions

Posted 1 year ago by ImArtur

I have some questions.

  1. In TDD tutorial 4: https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/4 Jeffrey said that some people would say that this peace of code:

$thread->owner->name

Could be anti-pattern for some laravel developers. I don't understand why. Jeffrey said that some developers would create new method to return $this->owner->name

  1. Mutators in laravel are really unclear to me. When should I use them? For example, in laravel docs. there is this peace of code:

public function getFullNameAttribute() { return "{$this->first_name} {$this->last_name}"; }

Isn't it a anti-pattern? There are presenters to transform this kind of data and pass it to the view. Am I wrong, why? In what cases should I use them?

If i'm not wrong, are docs wrong? Could you please explain the real good example of using Mutators?

Thanks.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.