3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravel8 Jetstream / Fortify のURLを変更する

Posted at

やりたいこと

認証とかのURLを変更したい

やりかた

Fortify

FortifyServiceProviderregisterメソッドにFortify::ignoreRoutes();を追加。

~~

class FortifyServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        Fortify::ignoreRoutes();
    }

~~

routesフォルダ内にfortify.phpを作成する。

vendor\laravel\fortify\routes\routes.phpの中身をコピーして先ほど作成したfortify.phpに貼り付ける。
(fortifyはなぜかpublishが用意されていない)

あとはRouteServiceProvideにルーティングとして登録する。

class RouteServiceProvider extends ServiceProvider
{
~ 省略 ~
    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        $this->configureRateLimiting();

        $this->routes(function () {
            Route::prefix('api')
                ->middleware('api')
                ->namespace($this->namespace)
                ->group(base_path('routes/api.php'));

            Route::middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/web.php'));

            // 追加
            Route::middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/fortify.php'));
        });
    }

あとはよしなにルーティングをいじる。

JetStream

JetstreamServiceProviderregisterメソッドにJetstream::ignoreRoutes();を追加。

~省略~

class JetstreamServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        Jetstream::ignoreRoutes();
    }

Jetstreamのルーティングファイルを公開する。

php artisan vendor:publish --tag=jetstream-routes

あとはRouteServiceProvideにルーティングとして登録する。

class RouteServiceProvider extends ServiceProvider
{
~ 省略 ~
    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        $this->configureRateLimiting();

        $this->routes(function () {
            Route::prefix('api')
                ->middleware('api')
                ->namespace($this->namespace)
                ->group(base_path('routes/api.php'));

            Route::middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/web.php'));

            Route::middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/fortify.php'));

            // 追加
            Route::middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/jetstream.php'));
        });
    }

あとはよしなにルーティングをいじる。

認証系のルーティングでauthにして1ファイルにまとめたりしても良いかも

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?