laravel-starter-kit maintained by pyaesoneaung
Laravel Starter Kit
Laravel 12 starter kit with built-in strict typing, enhanced code quality tools, and safety features.
Installation
laravel new --using pyaesoneaung/laravel-starter-kit --git
Setup Git Hooks
npm install
Features
✅ Strict Models
Model::shouldBeStrict();
This does three things:
- Prevents lazy loading
- It prevents silently discarding attributes.
- It prevents accessing missing attributes.
✋ Prevent Destructive Commands
Preventing the execution of destructive commands in production environments.
DB::prohibitDestructiveCommands(app()->isProduction());
⚡️ Automatic Relation Loading
Laravel can automatically eager load the relationships you access.
Model::automaticallyEagerLoadRelationships();
🪝 Git Commit Hook
Run duster lint for PHPStan, duster fix for refactor with Rector, and format with Laravel Pint before every commit.
Default Laravel Rector Rules
EloquentMagicMethodToQueryBuilderRector
use App\Models\User;
-$user = User::find(1);
+$user = User::query()->find(1);
EloquentWhereRelationTypeHintingParameterRector
-User::whereHas('posts', function ($query) {
+User::whereHas('posts', function (Builder $query) {
$query->where('is_published', true);
});
-$query->whereHas('posts', function ($query) {
+$query->whereHas('posts', function (Builder $query) {
$query->where('is_published', true);
});
EloquentWhereTypeHintClosureParameterRector
/** @var \Illuminate\Contracts\Database\Query\Builder $query */
-$query->where(function ($query) {
+$query->where(function (Builder $query) {
$query->where('id', 1);
});
ModelCastsPropertyToCastsMethodRector
use Illuminate\Database\Eloquent\Model;
class Person extends Model
{
- protected $casts = [
- 'age' => 'integer',
- ];
+ protected function casts(): array
+ {
+ return [
+ 'age' => 'integer',
+ ];
+ }
}
ScopeNamedClassMethodToScopeAttributedClassMethodRector
class User extends Model
{
- public function scopeActive($query)
+ #[\Illuminate\Database\Eloquent\Attributes\Scope]
+ protected function active($query)
{
return $query->where('active', 1);
}
}
WhereToWhereLikeRector
-$query->where('name', 'like', 'Rector');
-$query->orWhere('name', 'like', 'Rector');
-$query->where('name', 'like binary', 'Rector');
+$query->whereLike('name', 'Rector');
+$query->orWhereLike('name', 'Rector');
+$query->whereLike('name', 'Rector', true);
😺 GitHub Actions
Automated workflows for continuous integration, running Laravel Pint and PHPStan on every push and pull request.