Skip to content

Commit 8e30788

Browse files
authored
Merge pull request #133 from Lomkit/fix/quick-start-command-laravel-11
🐛 quick start command without api installed
2 parents a7279cd + 4f82814 commit 8e30788

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Diff for: src/Console/Commands/QuickStartCommand.php

+31
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Lomkit\Rest\Console\Commands;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Filesystem\Filesystem;
67
use Illuminate\Support\Str;
78
use Lomkit\Rest\Console\ResolvesStubPath;
89

@@ -41,9 +42,39 @@ public function handle()
4142
$this->setAppNamespace();
4243
$this->updateApiRoutes();
4344

45+
$this->uncommentApiRoutesFile();
46+
4447
$this->info('Laravel Rest Api is ready. Type \'php artisan route:list\' to see your new routes !');
4548
}
4649

50+
/**
51+
* Uncomment the API routes file in the application bootstrap file.
52+
*
53+
* @return void
54+
*/
55+
protected function uncommentApiRoutesFile()
56+
{
57+
$appBootstrapPath = $this->laravel->bootstrapPath('app.php');
58+
59+
$content = file_get_contents($appBootstrapPath);
60+
61+
if (str_contains($content, '// api: ')) {
62+
(new Filesystem())->replaceInFile(
63+
'// api: ',
64+
'api: ',
65+
$appBootstrapPath,
66+
);
67+
} elseif (str_contains($content, 'web: __DIR__.\'/../routes/web.php\',') && !str_contains($content, 'api: __DIR__.\'/../routes/api.php\',')) {
68+
(new Filesystem())->replaceInFile(
69+
'web: __DIR__.\'/../routes/web.php\',',
70+
'web: __DIR__.\'/../routes/web.php\','.PHP_EOL.' api: __DIR__.\'/../routes/api.php\',',
71+
$appBootstrapPath,
72+
);
73+
} else {
74+
$this->components->warn('Unable to automatically add API route definition to bootstrap file. API route file should be registered manually if you did not already run `php artisan install:api`.');
75+
}
76+
}
77+
4778
/**
4879
* Update the User model namespace in the generated files.
4980
*

0 commit comments

Comments
 (0)