├── .php-cs-fixer.php ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json ├── src ├── Canvas │ └── Package.php ├── StubsPublishCommand.php └── StubsServiceProvider.php └── stubs ├── cast.inbound.stub ├── cast.stub ├── class.invokable.stub ├── class.stub ├── console.stub ├── controller.api.stub ├── controller.invokable.stub ├── controller.model.api.stub ├── controller.model.stub ├── controller.nested.api.stub ├── controller.nested.singleton.api.stub ├── controller.nested.singleton.stub ├── controller.nested.stub ├── controller.plain.stub ├── controller.singleton.api.stub ├── controller.singleton.stub ├── controller.stub ├── enum.backed.stub ├── enum.stub ├── event.stub ├── factory.stub ├── job.queued.stub ├── job.stub ├── listener.queued.stub ├── listener.typed.queued.stub ├── listener.typed.stub ├── mail.stub ├── markdown-mail.stub ├── markdown-notification.stub ├── middleware.stub ├── migration.create.stub ├── migration.stub ├── migration.update.stub ├── model.pivot.stub ├── model.stub ├── notification.stub ├── observer.plain.stub ├── observer.stub ├── pest.stub ├── pest.unit.stub ├── policy.plain.stub ├── policy.stub ├── provider.stub ├── request.stub ├── resource-collection.stub ├── resource.stub ├── rule.stub ├── scope.stub ├── seeder.stub ├── test.stub ├── test.unit.stub ├── trait.stub └── view-component.stub /.php-cs-fixer.php: -------------------------------------------------------------------------------- 1 | in([ 5 | __DIR__ . '/src', 6 | __DIR__ . '/tests', 7 | ]) 8 | ->name('*.php') 9 | ->notName('*.blade.php') 10 | ->ignoreDotFiles(true) 11 | ->ignoreVCS(true); 12 | 13 | return (new PhpCsFixer\Config()) 14 | ->setRules([ 15 | '@PSR12' => true, 16 | 'array_syntax' => ['syntax' => 'short'], 17 | 'ordered_imports' => ['sort_algorithm' => 'alpha'], 18 | 'no_unused_imports' => true, 19 | 'not_operator_with_successor_space' => true, 20 | 'trailing_comma_in_multiline' => true, 21 | 'phpdoc_scalar' => true, 22 | 'unary_operator_spaces' => true, 23 | 'binary_operator_spaces' => true, 24 | 'blank_line_before_statement' => [ 25 | 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], 26 | ], 27 | 'phpdoc_single_line_var_spacing' => true, 28 | 'phpdoc_var_without_name' => true, 29 | 'method_argument_space' => [ 30 | 'on_multiline' => 'ensure_fully_multiline', 31 | 'keep_multiple_spaces_after_comma' => true, 32 | ], 33 | 'single_trait_insert_per_statement' => true, 34 | ]) 35 | ->setFinder($finder); 36 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-stubs` will be documented in this file 4 | 5 | ## 3.1.1 - 2025-02-20 6 | 7 | ### What's Changed 8 | 9 | * Laravel 12.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-stubs/pull/35 10 | 11 | ### New Contributors 12 | 13 | * @laravel-shift made their first contribution in https://github.com/spatie/laravel-stubs/pull/35 14 | 15 | **Full Changelog**: https://github.com/spatie/laravel-stubs/compare/3.1.0...3.1.1 16 | 17 | ## 3.1.0 - 2024-09-18 18 | 19 | ### What's Changed 20 | 21 | * Updates by @Nielsvanpach in https://github.com/spatie/laravel-stubs/pull/33 22 | * Adds missing return types by @jsandfordhughescoop in https://github.com/spatie/laravel-stubs/pull/34 23 | 24 | ### New Contributors 25 | 26 | * @Nielsvanpach made their first contribution in https://github.com/spatie/laravel-stubs/pull/33 27 | * @jsandfordhughescoop made their first contribution in https://github.com/spatie/laravel-stubs/pull/34 28 | 29 | **Full Changelog**: https://github.com/spatie/laravel-stubs/compare/3.0.0...3.1.0 30 | 31 | ## 3.0.0 - 2024-03-08 32 | 33 | ### What's Changed 34 | 35 | * Add L11 stubs 36 | * Simplify request and factory by @mokhosh in https://github.com/spatie/laravel-stubs/pull/32 37 | 38 | ## 2.5.4 - 2024-02-14 39 | 40 | ### What's Changed 41 | 42 | * remove unnecessary dockblocks by @mokhosh in https://github.com/spatie/laravel-stubs/pull/28 43 | * add laravel 11 support by @mokhosh in https://github.com/spatie/laravel-stubs/pull/29 44 | 45 | ### New Contributors 46 | 47 | * @mokhosh made their first contribution in https://github.com/spatie/laravel-stubs/pull/28 48 | 49 | **Full Changelog**: https://github.com/spatie/laravel-stubs/compare/2.5.3...2.5.4 50 | 51 | ## 2.5.3 - 2023-12-21 52 | 53 | ### What's Changed 54 | 55 | * Update rule stub by @Carnicero90 in https://github.com/spatie/laravel-stubs/pull/27 56 | 57 | ### New Contributors 58 | 59 | * @Carnicero90 made their first contribution in https://github.com/spatie/laravel-stubs/pull/27 60 | 61 | **Full Changelog**: https://github.com/spatie/laravel-stubs/compare/2.5.2...2.5.3 62 | 63 | ## 2.5.2 - 2023-01-23 64 | 65 | - support L10 66 | 67 | ## 2.5.1 - 2023-01-15 68 | 69 | ### What's Changed 70 | 71 | - Polish stubs (by @freekmurze) 72 | - Convert all tests to pest by @alexmanase in https://github.com/spatie/laravel-stubs/pull/26 73 | 74 | ### New Contributors 75 | 76 | - @alexmanase made their first contribution in https://github.com/spatie/laravel-stubs/pull/26 77 | 78 | **Full Changelog**: https://github.com/spatie/laravel-stubs/compare/2.5.0...2.5.1 79 | 80 | ## 2.5.0 - 2022-09-14 81 | 82 | - use invokable rule by default 83 | 84 | ## 2.4.4 - 2022-07-29 85 | 86 | ### What's Changed 87 | 88 | - Updated factory stub to use generics by @Xammie in https://github.com/spatie/laravel-stubs/pull/21 89 | 90 | **Full Changelog**: https://github.com/spatie/laravel-stubs/compare/2.4.3...2.4.4 91 | 92 | ## 2.4.3 - 2022-02-09 93 | 94 | ## What's Changed 95 | 96 | - Add event stub by @geidelguerra in https://github.com/spatie/laravel-stubs/pull/19 97 | 98 | **Full Changelog**: https://github.com/spatie/laravel-stubs/compare/2.4.2...2.4.3 99 | 100 | ## 2.4.2 - 2022-02-07 101 | 102 | ## What's Changed 103 | 104 | - Remove docblock from policy method by @Xammie in https://github.com/spatie/laravel-stubs/pull/18 105 | 106 | ## New Contributors 107 | 108 | - @Xammie made their first contribution in https://github.com/spatie/laravel-stubs/pull/18 109 | 110 | **Full Changelog**: https://github.com/spatie/laravel-stubs/compare/2.4.1...2.4.2 111 | 112 | ## 2.4.1 - 2022-02-03 113 | 114 | ## What's Changed 115 | 116 | - Move orchestra/testbench to dev dependencies by @geidelguerra in https://github.com/spatie/laravel-stubs/pull/17 117 | 118 | ## New Contributors 119 | 120 | - @geidelguerra made their first contribution in https://github.com/spatie/laravel-stubs/pull/17 121 | 122 | **Full Changelog**: https://github.com/spatie/laravel-stubs/compare/2.4.0...2.4.1 123 | 124 | ## 2.4.0 - 2022-01-14 125 | 126 | - support Laravel 9 127 | 128 | ## 2.3.1 - 2021-12-01 129 | 130 | ## What's Changed 131 | 132 | - Fix php-cs-fixer by @erikn69 in https://github.com/spatie/laravel-stubs/pull/15 133 | - Improved behaviour when stubs are updated by @chrisinit in https://github.com/spatie/laravel-stubs/pull/16 134 | 135 | ## New Contributors 136 | 137 | - @erikn69 made their first contribution in https://github.com/spatie/laravel-stubs/pull/15 138 | - @chrisinit made their first contribution in https://github.com/spatie/laravel-stubs/pull/16 139 | 140 | **Full Changelog**: https://github.com/spatie/laravel-stubs/compare/2.3.0...2.3.1 141 | 142 | ## 2.3.0 - 2021-11-10 143 | 144 | ## What's Changed 145 | 146 | - Update php-cs-fixer.yml by @llabbasmkhll in https://github.com/spatie/laravel-stubs/pull/13 147 | - Publish service provider stub by @mikemand in https://github.com/spatie/laravel-stubs/pull/14 148 | 149 | ## New Contributors 150 | 151 | - @llabbasmkhll made their first contribution in https://github.com/spatie/laravel-stubs/pull/13 152 | - @mikemand made their first contribution in https://github.com/spatie/laravel-stubs/pull/14 153 | 154 | **Full Changelog**: https://github.com/spatie/laravel-stubs/compare/2.2.0...2.3.0 155 | 156 | ## 2.2.0 - 2021-07-08 157 | 158 | - use anonymous migrations by default 159 | 160 | ## 2.1.0 - 2020-12-02 161 | 162 | - add support for PHP 8 163 | 164 | ## 2.0.1 - 2020-10-03 165 | 166 | - use `HasFactory` by default 167 | 168 | ## 2.0.0 - 2020-09-14 169 | 170 | - add Laravel 8 specific stubs 171 | 172 | ## 1.1.1 - 2020-09-09 173 | 174 | - allow Laravel 8 175 | 176 | ## 1.1.0 - 2020-03-25 177 | 178 | - integration with orchestra/canvas (#7) 179 | 180 | ## 1.0.3 - 2020-03-24 181 | 182 | - fix console output color 183 | 184 | ## 1.0.2 - 2020-03-24 185 | 186 | - fix `--force` option 187 | 188 | ## 1.0.1 - 2020-03-24 189 | 190 | - fix service provider name 191 | 192 | ## 1.0.0 - 2020-03-24 193 | 194 | - initial release 195 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Spatie bvba 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Opinionated Laravel stubs 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-stubs.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-stubs) 4 | [![run-tests](https://github.com/spatie/laravel-stubs/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-stubs/actions/workflows/run-tests.yml) 5 | [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-stubs.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-stubs) 6 | 7 | This repo contains opinionated versions of the Laravel stubs. The most notable changes are: 8 | 9 | - migrations don't have a `down` function 10 | - controllers don't extend a base controller 11 | - none of the model attributes are guarded 12 | - use return type hints where possible 13 | - most docblocks have been removed 14 | 15 | ## Support us 16 | 17 | [](https://spatie.be/github-ad-click/laravel-stubs) 18 | 19 | We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). 20 | 21 | We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). 22 | 23 | ## Exploring laravel-stubs 24 | 25 | In this [video on YouTube](https://www.youtube.com/watch?v=I-y-VSOL93I), Povilas Korop explores our package. 26 | 27 | ## Installation 28 | 29 | You can install the package via composer: 30 | 31 | ```bash 32 | composer require spatie/laravel-stubs --dev 33 | ``` 34 | 35 | If you want to keep your stubs up to date with every update, add this composer hook to your composer.json file: 36 | 37 | ```json 38 | "scripts": { 39 | "post-update-cmd": [ 40 | "@php artisan spatie-stub:publish --force" 41 | ] 42 | } 43 | ``` 44 | 45 | ## Usage 46 | 47 | You can publish the stubs using this command: 48 | 49 | ```bash 50 | php artisan spatie-stub:publish 51 | ``` 52 | 53 | ## Testing 54 | 55 | ``` bash 56 | composer test 57 | ``` 58 | 59 | ## Changelog 60 | 61 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 62 | 63 | ## Contributing 64 | 65 | Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details. 66 | 67 | ## Security 68 | 69 | If you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker. 70 | 71 | ## Credits 72 | 73 | - [Freek Van der Herten](https://github.com/freekmurze) 74 | - [All Contributors](../../contributors) 75 | 76 | ## License 77 | 78 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 79 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "spatie/laravel-stubs", 3 | "description": "Opinionated Laravel stubs", 4 | "keywords": [ 5 | "spatie", 6 | "laravel-stubs" 7 | ], 8 | "homepage": "https://github.com/spatie/laravel-stubs", 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "Freek Van der Herten", 13 | "email": "freek@spatie.be", 14 | "homepage": "https://spatie.be", 15 | "role": "Developer" 16 | } 17 | ], 18 | "require": { 19 | "php": "^8.2", 20 | "laravel/framework": "^11.0|^12.0" 21 | }, 22 | "require-dev": { 23 | "mockery/mockery": "^1.4", 24 | "orchestra/testbench": "^9.0|^10.0", 25 | "pestphp/pest": "^2.0|^3.7" 26 | }, 27 | "autoload": { 28 | "psr-4": { 29 | "Spatie\\Stubs\\": "src" 30 | } 31 | }, 32 | "autoload-dev": { 33 | "psr-4": { 34 | "Spatie\\Stubs\\Tests\\": "tests" 35 | } 36 | }, 37 | "scripts": { 38 | "format": "vendor/bin/php-cs-fixer fix", 39 | "test": "vendor/bin/pest", 40 | "test-coverage": "vendor/bin/pest --coverage-html coverage" 41 | }, 42 | "config": { 43 | "sort-packages": true, 44 | "allow-plugins": { 45 | "pestphp/pest-plugin": true 46 | } 47 | }, 48 | "extra": { 49 | "laravel": { 50 | "providers": [ 51 | "Spatie\\Stubs\\StubsServiceProvider" 52 | ] 53 | } 54 | }, 55 | "minimum-stability": "dev", 56 | "prefer-stable": true 57 | } 58 | -------------------------------------------------------------------------------- /src/Canvas/Package.php: -------------------------------------------------------------------------------- 1 | confirmToProceed()) { 23 | return 1; 24 | } 25 | 26 | if (! is_dir($stubsPath = $this->laravel->basePath('stubs'))) { 27 | (new Filesystem())->makeDirectory($stubsPath); 28 | } 29 | 30 | $files = collect(File::files(__DIR__.'/../stubs')) 31 | ->unless($this->option('force'), fn ($files) => $this->unpublished($files)); 32 | 33 | $published = $this->publish($files); 34 | 35 | $this->info("{$published} / {$files->count()} stubs published."); 36 | } 37 | 38 | public function unpublished(Collection $files): Collection 39 | { 40 | return $files->reject(function (SplFileInfo $file) { 41 | return file_exists($this->targetPath($file)); 42 | }); 43 | } 44 | 45 | public function publish(Collection $files): int 46 | { 47 | return $files->reduce(function (int $published, SplFileInfo $file) { 48 | file_put_contents($this->targetPath($file), file_get_contents($file->getPathname())); 49 | 50 | return $published + 1; 51 | }, 0); 52 | } 53 | 54 | public function targetPath(SplFileInfo $file): string 55 | { 56 | return "{$this->laravel->basePath('stubs')}/{$file->getFilename()}"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/StubsServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->runningInConsole()) { 12 | $this->commands([ 13 | StubsPublishCommand::class, 14 | ]); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /stubs/cast.inbound.stub: -------------------------------------------------------------------------------- 1 | 38 | */ 39 | public function attachments(): array 40 | { 41 | return []; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /stubs/markdown-notification.stub: -------------------------------------------------------------------------------- 1 | markdown('{{ view }}'); 27 | } 28 | 29 | public function toArray(object $notifiable): array 30 | { 31 | return [ 32 | // 33 | ]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /stubs/middleware.stub: -------------------------------------------------------------------------------- 1 | id(); 13 | $table->timestamps(); 14 | }); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /stubs/migration.stub: -------------------------------------------------------------------------------- 1 | line('The introduction to the notification.') 28 | ->action('Notification Action', url('/')) 29 | ->line('Thank you for using our application!'); 30 | } 31 | 32 | public function toArray(object $notifiable): array 33 | { 34 | return [ 35 | // 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /stubs/observer.plain.stub: -------------------------------------------------------------------------------- 1 | get('/'); 5 | 6 | $response->assertStatus(200); 7 | }); 8 | -------------------------------------------------------------------------------- /stubs/pest.unit.stub: -------------------------------------------------------------------------------- 1 | toBeTrue(); 5 | }); 6 | -------------------------------------------------------------------------------- /stubs/policy.plain.stub: -------------------------------------------------------------------------------- 1 | assertTrue(true); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /stubs/trait.stub: -------------------------------------------------------------------------------- 1 |