1
0

More than 3 years have passed since last update.

なぜ、admin/profile/createに辿り着けないのか

Posted at

なぜ、admin/profile/createに辿り着けないのか

本題

こんにちは!今回はある問題にぶつかりました。。。

Laravel にて admin/profile/create にいきたいのだが、
なぜか、アクセスすると
404 not foundと表示されます。
Routing の記述ミスなのかとか、Action のミスなのか色々考えたのですが、
とりあえずは
web.php ファイルを
見てみるのが良いとネットに書いてありましたので見に行ってみました。

Route::get('/', function () {
    return view('welcome');
});

Route::group(['prefix' => 'admin'], function() {
    Route::get('news/create', 'Admin\NewsController@add')->middleware('auth');
    Route::get('admin/profile/create', 'Admin\NewsController@add');
    Route::get('admin/profile/edit', 'Admin\NewsController@edit');
});
Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

ふむふむ、特に変わったものはないのだけど、
わからなすぎて困惑しました。

しかし、友人に尋ねてみたら速攻で間違いが判明しました。

<友人A
お前これさ、「admin/admin/profile/create」になってね?

<私

何言ってんだ、、、あ。。
なってるわ笑

<友人A
wwwww

<私
wwwww

友人の言った通り「admin/admin/profile/create」なっていました。。泣
問題の部分はここです。

Route::group(['prefix' => 'admin'], function() {
    Route::get('news/create', 'Admin\NewsController@add')->middleware('auth');
    Route::get('admin/profile/create', 'Admin\NewsController@add');
    Route::get('admin/profile/edit', 'Admin\NewsController@edit');
});

お分かりでしょうか。
groupの中の['prefix' => 'admin']と記述しているのに、

Route::get('admin/profile/create', 'Admin\NewsController@add');
Route::get('admin/profile/edit', 'Admin\NewsController@edit');

と記述してしまっているのです。
ちなみに['prefix' => 'admin']の記述は、すべて admin から始まると言うことです。

ですので、この記述だと
adminからスタート → admin/profile/create', 'Admin\NewsController@add
なってしまうと言うことですね。

直します。笑

Route::group(['prefix' => 'admin'], function() {
    Route::get('news/create', 'Admin\NewsController@add')->middleware('auth');
    Route::get('profile/create', 'Admin\NewsController@add');
    Route::get('profile/edit', 'Admin\NewsController@edit');
});

こう言うことですね!
解決です!!
友人Aよ!ありがとう。
皆さんも私みたいにならないように、お気をつけくださいませ!笑

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