Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 quick start command without api installed #133

Merged
merged 2 commits into from
Aug 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/Console/Commands/QuickStartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Lomkit\Rest\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
use Lomkit\Rest\Console\ResolvesStubPath;

Expand Down Expand Up @@ -41,9 +42,39 @@ public function handle()
$this->setAppNamespace();
$this->updateApiRoutes();

$this->uncommentApiRoutesFile();

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

/**
* Uncomment the API routes file in the application bootstrap file.
*
* @return void
*/
protected function uncommentApiRoutesFile()
{
$appBootstrapPath = $this->laravel->bootstrapPath('app.php');

$content = file_get_contents($appBootstrapPath);

if (str_contains($content, '// api: ')) {
(new Filesystem())->replaceInFile(
'// api: ',
'api: ',
$appBootstrapPath,
);
} elseif (str_contains($content, 'web: __DIR__.\'/../routes/web.php\',') && !str_contains($content, 'api: __DIR__.\'/../routes/api.php\',')) {
(new Filesystem())->replaceInFile(
'web: __DIR__.\'/../routes/web.php\',',
'web: __DIR__.\'/../routes/web.php\','.PHP_EOL.' api: __DIR__.\'/../routes/api.php\',',
$appBootstrapPath,
);
} else {
$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`.');
}
}

/**
* Update the User model namespace in the generated files.
*
Expand Down