Laravel路线视图名称声明未显示

时间:2019-06-28 02:21:40

标签: laravel routes

我已经在routes/web.php中创建了路线。

Route::prefix('home')->group(function () {
    Route::view('/', 'landing.index', ['name' => 'landing.home']);
    Route::post('/', 'SignupController@signup');
    Route::view('thank-you', 'landing.thank-you', ['name' => 'landing.thankyou']);
});

但是,呼叫php artisan route:list时会显示:

| Domain | Method   | URI            | Name  | Action                                             | Middleware  |
+--------+----------+----------------+-------+----------------------------------------------------+-------------+
|        | GET|HEAD | home           |       | Illuminate\Routing\ViewController                  | web         |
|        | POST     | home           |       | App\Http\Controllers\SignupController@signup       | web         |
|        | GET|HEAD | home/thank-you |       | Illuminate\Routing\ViewController                  | web         |

此外,该名称尚未注册。

2 个答案:

答案 0 :(得分:0)

尝试一下:

Route::prefix('home')->group(function () {
 Route::view('/', 'landing.index')->name('landing.home');
    Route::post('/', 'SignupController@signup');
    Route::view('thank-you', 'landing.thank-you')->name('landing.thankyou');
});

希望有帮助。

答案 1 :(得分:0)

这样的名称声明:

Route::prefix('home')->group(function () {

    Route::view('/', 'landing.index', ['name' => 'landing.home'])->name("home");
    Route::post('/', 'SignupController@signup')->name("home");
    Route::view('thank-you', 'landing.thank-you', ['name' => 'landing.thankyou'])->name("thank-you");

});

生成URL

$url = route('home');

生成重定向

return redirect()->route('home');