Source: martinjoo.dev

Blog for Laravel Artisans
This article is all about writing maintainable Laravel code in general. I've been (mostly) a PHP (90% Laravel) developer since 2012 and I've been reviewing code since around 2017.

Consider the following snippet: class Post extends Model { public function comments(): HasMany { return $this->hasMany(Comment::class); }} class PostController { public function index() { foreach (Post::all() as $post) { $comments = $post->comments; }} }

Consider this class: class PostResource extends JsonResource { public function toArray($request) { return [ 'title' => $this->title, 'content' => $this->content, 'comments' => CommentResource::collection( $this->comments ), ]; }}

Gimme some Laravel code: public function up() { Schema::create('posts', function (Blueprint $table) { $table->id(); $table->string('title'); $table->string('body'); $table->dateTime('published_at')->index(); $table->timestamps(); }); }
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners