如何使用 Inertia JS 在 Laravel 中默认编辑或删除身份验证的 URL?

Posted

技术标签:

【中文标题】如何使用 Inertia JS 在 Laravel 中默认编辑或删除身份验证的 URL?【英文标题】:How can I to edit or remove the URLs of the authentication by default in Laravel using Inertia JS? 【发布时间】:2021-08-26 21:21:40 【问题描述】:

我正在使用 Laravel 8 和 Inertia JS 和 VueJS 开始一个新项目。我正在使用 Inertia 生成的身份验证路由和视图,但在我的应用程序中我不需要 /register url,因此我需要将其删除以避免其他人输入 URL。

我怎样才能删除它?或者管理 Inertia 生成的 url 的地方在哪里?或者例如,如果我不想删除网址,但我想将其重命名为/signup,我该怎么做?

我一直在惯性文档中寻找信息,但没有找到任何信息。

这是我的 web.php 路由文件,这些路由不在这里

<?php

use App\Http\Controllers\Experimental\RandomController;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () 
    return Inertia::render('Welcome', [
        'canLogin' => Route::has('login'),
        'canRegister' => Route::has('register'),
        'laravelVersion' => Application::VERSION,
        'phpVersion' => PHP_VERSION,
    ]);
);

Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () 
    return Inertia::render('Dashboard');
)->name('dashboard');

更新 1: 我正在使用 Laravel Jetstream

【问题讨论】:

你在使用 Laravel Jetstream 吗? 是的,很抱歉。我忘了把它放在问题中。已更新。 【参考方案1】:

他们似乎没有记录如何做到这一点,但从 Fortify 配置文件中看起来是可行的。

打开config/fortify.php 并从数组中注释或删除Features::registration(),

use Laravel\Fortify\Features;

'features' => [
    // Features::registration(),
    // ...
],

【讨论】:

【参考方案2】:

检查路由下的auth.php,你应该在那里找到所有的auth路由。因此,您可以重命名注册 url 以注册并创建新控制器或重命名注册用户控制器。

【讨论】:

以上是关于如何使用 Inertia JS 在 Laravel 中默认编辑或删除身份验证的 URL?的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 Inertia Js、Vue 和 Laravel 重新加载持久布局或观看道具

使用 Vue.Js / Inertia.js 和 Laravel 对结果进行分页

使用 laravel Inertia JS Vuetify DataTable

在 Inertia.js Vue 文件中访问 Laravel 的 .env 变量

Laravel 8 + Inertia 不渲染变量

如何在 Laravel 8 模块中使用 InertiaJS 加载 Vue 组件