LoginSignup
0
0

More than 3 years have passed since last update.

Laravel8をノリで使ってみたらTarget class [◯◯Controller] does not existと表示された

Posted at

今までLaravle6や7でアプリなどを作っていたが8にバージョンアップになったと聞いて早速8を使ってみたら、今まで見たことないエラーメッセージが表示されたのでここにメモとして残すことにした。

記述したコード
routes/web.php
<?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('/','BbsController@index');

App\Http\Controllers\BbsController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class BbsController extends Controller
{
//
public function index(){
return view('Bbs.index');
}
}

いつもの通りこれで画面表示されるだろと思ったらまさかのTarget class [BbsController] does not exist.と表示された。

よくよく調べてみたらLaravel8からルーティングの書き方が変わったらしく以下のように修正したら正常に動作した

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\BbsController;

/*
|--------------------------------------------------------------------------
| 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('/', [BbsController::class,'index']);

どうやら作成したControllerのパスとルーティングの書き方を上のようにしないといけなくなったらしい。

まだまだLaravel8の変更点があるらしいので公式ドキュメントを見ようと思った。

0
0
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
0
0