Laravel9 ルーティングの書き方

Laravel

環境 Windows11 Apache 2.4.53 PHP8.1 Postgresql14.2 Laravel v9.8.1

※環境が変わりました。

参考サイト

以下のサイトに感謝です。
Laravel8 新しいルーティングの書き方

HelloControllerを作成してメソッド act1 を定義し、http://localhost/hello/act1で起動したい場合

Laravel8以降

<?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\HelloController;
// 追加

/*
|--------------------------------------------------------------------------
| 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('/hello/act1', [HelloController::class, 'act1']);

Laravel7まで

<?php

use Illuminate\Support\Facades\Route;
// 何も書かない
/*
|--------------------------------------------------------------------------
| 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('/hello/act1', 'HelloController@act1');

googleで検索するとこちらが多くヒットしているので混乱しました。ようは正式なドキュメントを確認しなさいという事ですね。

コメント

タイトルとURLをコピーしました