Skip to content

Commit

Permalink
[develop] Adds L11 support (#257) (#259)
Browse files Browse the repository at this point in the history
* Adds L11 support

* Fixes missing readme

* Removes references to `RouteServiceProvider`

* Injects `Controller` stub

* Adds missing `.php` suffix

* Fixes stubs

* Overrides service provider if needed

* Fixes namespace

* Redirects home

* docs

* Installs `2014_10_12_100000_create_password_resets_table` for older Laravel versions

* Only copies reset passports before Laravel 11
  • Loading branch information
nunomaduro committed Jan 12, 2024
1 parent 7fa676b commit 7335d70
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 29 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/tests.yml
Expand Up @@ -17,10 +17,14 @@ jobs:
fail-fast: true
matrix:
php: ['8.0', 8.1, 8.2, 8.3]
laravel: [9, 10]
laravel: [9, 10, 11]
exclude:
- php: '8.0'
laravel: 10
- php: '8.0'
laravel: 11
- php: '8.1'
laravel: 11
- php: 8.3
laravel: 9

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -21,7 +21,7 @@ Only the latest major version of Laravel UI receives bug fixes. The table below
| [1.x](https://github.com/laravel/ui/tree/1.x) | 5.8, 6.x |
| [2.x](https://github.com/laravel/ui/tree/2.x) | 7.x |
| [3.x](https://github.com/laravel/ui/tree/3.x) | 8.x |
| [4.x](https://github.com/laravel/ui/tree/4.x) | 9.x, 10.x |
| [4.x](https://github.com/laravel/ui/tree/4.x) | 9.x, 10.x, 11.x |

### Installation

Expand Down
12 changes: 6 additions & 6 deletions composer.json
Expand Up @@ -11,14 +11,14 @@
],
"require": {
"php": "^8.0",
"illuminate/console": "^9.21|^10.0",
"illuminate/filesystem": "^9.21|^10.0",
"illuminate/support": "^9.21|^10.0",
"illuminate/validation": "^9.21|^10.0"
"illuminate/console": "^9.21|^10.0|^11.0",
"illuminate/filesystem": "^9.21|^10.0|^11.0",
"illuminate/support": "^9.21|^10.0|^11.0",
"illuminate/validation": "^9.21|^10.0|^11.0"
},
"require-dev": {
"orchestra/testbench": "^7.0|^8.0",
"phpunit/phpunit": "^9.3"
"orchestra/testbench": "^7.0|^8.0|^9.0",
"phpunit/phpunit": "^9.3|^10.4"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 12 additions & 0 deletions src/Auth/stubs/controllers/Controller.stub
@@ -0,0 +1,12 @@
<?php

namespace {{namespace}}Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
use AuthorizesRequests, ValidatesRequests;
}
33 changes: 23 additions & 10 deletions src/AuthCommand.php
Expand Up @@ -117,35 +117,48 @@ protected function exportBackend()

if (file_exists($controller) && ! $this->option('force')) {
if ($this->components->confirm("The [HomeController.php] file already exists. Do you want to replace it?")) {
file_put_contents($controller, $this->compileControllerStub());
file_put_contents($controller, $this->compileStub('controllers/HomeController'));
}
} else {
file_put_contents($controller, $this->compileControllerStub());
file_put_contents($controller, $this->compileStub('controllers/HomeController'));
}

$baseController = app_path('Http/Controllers/Controller.php');

if (file_exists($baseController) && ! $this->option('force')) {
if ($this->components->confirm("The [Controller.php] file already exists. Do you want to replace it?")) {
file_put_contents($baseController, $this->compileStub('controllers/Controller'));
}
} else {
file_put_contents($baseController, $this->compileStub('controllers/Controller'));
}

if (! file_exists(database_path('migrations/0001_01_01_000000_create_users_table.php'))) {
copy(
__DIR__.'/../stubs/migrations/2014_10_12_100000_create_password_resets_table.php',
base_path('database/migrations/2014_10_12_100000_create_password_resets_table.php')
);
}

file_put_contents(
base_path('routes/web.php'),
file_get_contents(__DIR__.'/Auth/stubs/routes.stub'),
FILE_APPEND
);

copy(
__DIR__.'/../stubs/migrations/2014_10_12_100000_create_password_resets_table.php',
base_path('database/migrations/2014_10_12_100000_create_password_resets_table.php')
);
}

/**
* Compiles the "HomeController" stub.
* Compiles the given stub.
*
* @param string $stub
* @return string
*/
protected function compileControllerStub()
protected function compileStub($stub)
{
return str_replace(
'{{namespace}}',
$this->laravel->getNamespace(),
file_get_contents(__DIR__.'/Auth/stubs/controllers/HomeController.stub')
file_get_contents(__DIR__.'/Auth/stubs/'.$stub.'.stub')
);
}

Expand Down
3 changes: 1 addition & 2 deletions stubs/Auth/ConfirmPasswordController.stub
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\ConfirmsPasswords;

class ConfirmPasswordController extends Controller
Expand All @@ -26,7 +25,7 @@ class ConfirmPasswordController extends Controller
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
protected $redirectTo = '/home';

/**
* Create a new controller instance.
Expand Down
3 changes: 1 addition & 2 deletions stubs/Auth/LoginController.stub
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
Expand All @@ -26,7 +25,7 @@ class LoginController extends Controller
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
protected $redirectTo = '/home';

/**
* Create a new controller instance.
Expand Down
3 changes: 1 addition & 2 deletions stubs/Auth/RegisterController.stub
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
Expand All @@ -29,7 +28,7 @@ class RegisterController extends Controller
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
protected $redirectTo = '/home';

/**
* Create a new controller instance.
Expand Down
3 changes: 1 addition & 2 deletions stubs/Auth/ResetPasswordController.stub
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\ResetsPasswords;

class ResetPasswordController extends Controller
Expand All @@ -26,5 +25,5 @@ class ResetPasswordController extends Controller
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
protected $redirectTo = '/home';
}
3 changes: 1 addition & 2 deletions stubs/Auth/VerificationController.stub
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\VerifiesEmails;

class VerificationController extends Controller
Expand All @@ -26,7 +25,7 @@ class VerificationController extends Controller
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
protected $redirectTo = '/home';

/**
* Create a new controller instance.
Expand Down
2 changes: 1 addition & 1 deletion tests/AuthBackend/ThrottleLoginsTest.php
Expand Up @@ -28,7 +28,7 @@ public function it_can_generate_throttle_key(string $email, string $expectedEmai
$this->assertSame($expectedEmail . '|192.168.0.1', $method->invoke($throttle, $request));
}

public function emailProvider(): array
public static function emailProvider(): array
{
return [
'lowercase special characters' => ['ⓣⓔⓢⓣ@ⓛⓐⓡⓐⓥⓔⓛ.ⓒⓞⓜ', 'test@laravel.com'],
Expand Down

0 comments on commit 7335d70

Please sign in to comment.