Main stub changes:
- controllers don't extend a base
Controller; - depending on the parameters passed, this also adds resources for controllers;
- migrations don't have a
downfunction; - model has
withandfillableby default; - docblocks have been removed;
Install the package via composer:
composer require erikaraujo/laravel-stubs --devIf you want to keep your stubs up to date with every update, add this composer hook to your composer.json file:
"scripts": {
"post-update-cmd": [
"@php artisan erikaraujo-stub:publish --force"
]
}*note that this has a force parameter, which will make the new stubs overwrite the existing ones on the stubs folder.
Publish the stubs using this artisan command:
php artisan erikaraujo-stub:publish--force
php artisan erikaraujo-stub:publish --softdeletesUnless you use --force, none of the existing stubs inside the ./stubs folder will be replaced.
--softdeletes
php artisan erikaraujo-stub:publish --softdeletesThis will automatically add the SoftDeletes trait to your model stubs, add $table->softdeletes() to your migration stubs and add forceDelete() and restore() methods to the controllers.
--inertia
php artisan erikaraujo-stub:publish --inertiaThis will import Inertia\Inertia to all your non-api controller stubs by default as well as add resources to the controllers methods (if a model is provided).
Resource example:
public function index()
{
return Inertia::render('{{ model }}/Index', [
'{{ modelVariable }}' => {{ model }}::paginate()->onEachSide(1),
]);
}--json
php artisan erikaraujo-stub:publish --jsonThis will add resources to all your api controllers and return a json response with the correct HTTP response code.
Resource example:
public function index()
{
${{ modelVariable }} = {{ model }}::all();
return response()->json([
'data' => ${{ modelVariable }},
'total' => ${{ modelVariable }}->count(),
], 200);
}- Multiple You can mix and match these options and everything will be applied correctly. All examples below are fine:
php artisan erikaraujo-stub:publish --inertia --softdeletesphp artisan erikaraujo-stub:publish --json --softdeletesphp artisan erikaraujo-stub:publish --json --inertia --softdeletesphp artisan erikaraujo-stub:publish --json --inertia --softdeletes --forceTODO: Add testing to cover all possible mix and match scenarios.
Please see CHANGELOG for more information on what has changed recently.
For now, just create a PR and I'll take a look.