-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a new api "stack" to Breeze. This stack removes all JS and CSS related scaffolding and installs controllers that properly handle the API authentication (powered by Sanctum) that would typically be required when authenticating a JavaScript SPA such as applications powered by Next.js / Nuxt.js, etc.
- Loading branch information
1 parent
d320a59
commit 61ffbd4
Showing
31 changed files
with
1,241 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
namespace Laravel\Breeze\Console; | ||
|
||
use Illuminate\Filesystem\Filesystem; | ||
|
||
trait InstallsApiStack | ||
{ | ||
/** | ||
* Install the API Breeze stack. | ||
* | ||
* @return void | ||
*/ | ||
protected function installApiStack() | ||
{ | ||
$files = new Filesystem; | ||
|
||
// Controllers... | ||
$files->ensureDirectoryExists(app_path('Http/Controllers/Auth')); | ||
$files->copyDirectory(__DIR__.'/../../stubs/api/App/Http/Controllers/Auth', app_path('Http/Controllers/Auth')); | ||
|
||
// Middleware... | ||
$files->copyDirectory(__DIR__.'/../../stubs/api/App/Http/Middleware', app_path('Http/Middleware')); | ||
|
||
$this->replaceInFile('// \Laravel\Sanctum\Http', '\Laravel\Sanctum\Http', app_path('Http/Kernel.php')); | ||
|
||
$this->replaceInFile( | ||
'\Illuminate\Auth\Middleware\EnsureEmailIsVerified::class', | ||
'\App\Http\Middleware\EnsureEmailIsVerified::class', | ||
app_path('Http/Kernel.php') | ||
); | ||
|
||
// Requests... | ||
$files->ensureDirectoryExists(app_path('Http/Requests/Auth')); | ||
$files->copyDirectory(__DIR__.'/../../stubs/api/App/Http/Requests/Auth', app_path('Http/Requests/Auth')); | ||
|
||
// Providers... | ||
$files->copyDirectory(__DIR__.'/../../stubs/api/App/Providers', app_path('Providers')); | ||
|
||
// Routes... | ||
copy(__DIR__.'/../../stubs/api/routes/api.php', base_path('routes/api.php')); | ||
copy(__DIR__.'/../../stubs/api/routes/web.php', base_path('routes/web.php')); | ||
copy(__DIR__.'/../../stubs/api/routes/auth.php', base_path('routes/auth.php')); | ||
|
||
// Configuration... | ||
$files->copyDirectory(__DIR__.'/../../stubs/api/config', config_path()); | ||
|
||
$this->replaceInFile( | ||
"'url' => env('APP_URL', 'http://localhost')", | ||
"'url' => env('APP_URL', 'http://localhost'),".PHP_EOL.PHP_EOL." 'frontend_url' => env('FRONTEND_URL', 'http://localhost:3000')", | ||
config_path('app.php') | ||
); | ||
|
||
// Environment... | ||
if (! $files->exists(base_path('.env'))) { | ||
copy(base_path('.env.example'), base_path('.env')); | ||
} | ||
|
||
$this->replaceInFile( | ||
'APP_URL=http://localhost', | ||
'APP_URL=http://localhost'.PHP_EOL.'FRONTEND_URL=http://localhost:3000', | ||
base_path('.env') | ||
); | ||
|
||
// Tests... | ||
$this->installTests(); | ||
|
||
$files->delete(base_path('tests/Feature/Auth/PasswordConfirmationTest.php')); | ||
|
||
// Cleaning... | ||
$this->removeScaffoldingUnnecessaryForApis(); | ||
|
||
$this->info('Breeze scaffolding installed successfully.'); | ||
} | ||
|
||
/** | ||
* Remove any application scaffolding that isn't needed for APIs. | ||
* | ||
* @return void | ||
*/ | ||
protected function removeScaffoldingUnnecessaryForApis() | ||
{ | ||
$files = new Filesystem; | ||
|
||
// Remove frontend related files... | ||
$files->delete(base_path('package.json')); | ||
$files->delete(base_path('webpack.mix.js')); | ||
|
||
// Remove Laravel "welcome" view... | ||
$files->delete(resource_path('views/welcome.blade.php')); | ||
$files->put(resource_path('views/.gitkeep'), PHP_EOL); | ||
|
||
// Remove CSS and JavaScript directories... | ||
$files->deleteDirectory(resource_path('css')); | ||
$files->deleteDirectory(resource_path('js')); | ||
} | ||
} |
Oops, something went wrong.