Skip to content

Commit

Permalink
Merge pull request #133 from Lomkit/fix/quick-start-command-laravel-11
Browse files Browse the repository at this point in the history
🐛 quick start command without api installed
  • Loading branch information
GautierDele authored Aug 11, 2024
2 parents a7279cd + 4f82814 commit 8e30788
Showing 1 changed file with 31 additions and 0 deletions.
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

0 comments on commit 8e30788

Please sign in to comment.