Best Practice Laravel

Prinsip single responsibility Kelas dan metode seharusnya hanya memiliki satu tanggung jawab. Contoh buruk: 1 2 3 4 5 6 7 8 public function getFullNameAttribute(): string { if (auth()->user() && auth()->user()->hasRole('client') && auth()->user()->isVerified()) { return 'Mr. ' . $this->first_name . ' ' . $this->middle_name . ' ' . $this->last_name; } else { return $this->first_name[0] . '. ' . $this->last_name; } } Contoh terbaik: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 public function getFullNameAttribute(): string { return $this->isVerifiedClient() ?...

Senin, 14 November 2022 · 8 menit · 1593 kata · Ihsan Devs