route、bladeがあるはずなのにNotFoundと出て困っています。
ここの「投稿する」をクリックすると
articles/create がNotFound...
■navbarのblade
<ul class="navbar-nav ml-auto"> @guest <li class="nav-item"> <a class="nav-link" href="{{ route('register') }}">ユーザー登録</a> {{--この行を変更--}} </li> @endguest @guest <li class="nav-item"> <a class="nav-link" href="{{ route('login') }}">ログイン</a> </li> @endguest @auth <li class="nav-item"> <a class="nav-link" href="{{ route('articles.create') }}"><i class="fas fa-pen mr-1"></i>投稿する</a> </li> @endauth @auth <!-- Dropdown --> ドロップダウンは省略。マイページ、ログアウトですが問題なく遷移します。 <!-- Dropdown --> @endauth </ul>
■route web.php
Auth::routes(); //ユーザー認証で追加 Route::get('/', 'ArticleController@index')->name('articles.index'); Route::resource('/articles', 'ArticleController')->only(['show']); //ログイン後の処理 Route::resource('/articles', 'ArticleController')->except(['index', 'show'])->middleware('auth'); //記事の追加・編集・削除・表示等 Route::prefix('articles')->name('articles.')->group(function () { Route::put('/{article}/like', 'ArticleController@like')->name('like')->middleware('auth'); Route::delete('/{article}/like', 'ArticleController@unlike')->name('unlike')->middleware('auth'); });
■php artisan route:listの結果
+--------+-----------+-------------------------+------------------+------------------------------------------------------------------------+---------------------------------+ | Domain | Method | URI | Name | Action | Middleware | +--------+-----------+-------------------------+------------------+------------------------------------------------------------------------+---------------------------------+ | | GET|HEAD | / | articles.index | App\Http\Controllers\ArticleController@index | web,can:viewAny,App\Article | | | POST | articles | articles.store | App\Http\Controllers\ArticleController@store | web,auth,can:create,App\Article | | | GET|HEAD | articles/create | articles.create | App\Http\Controllers\ArticleController@create | web,auth,can:create,App\Article | | | DELETE | articles/{article} | articles.destroy | App\Http\Controllers\ArticleController@destroy | web,auth,can:delete,article | | | PUT|PATCH | articles/{article} | articles.update | App\Http\Controllers\ArticleController@update | web,auth,can:update,article | | | GET|HEAD | articles/{article} | articles.show | App\Http\Controllers\ArticleController@show | web,can:view,article | | | GET|HEAD | articles/{article}/edit | articles.edit | App\Http\Controllers\ArticleController@edit | web,auth,can:update,article | | | DELETE | articles/{article}/like | articles.unlike | App\Http\Controllers\ArticleController@unlike | web,auth | | | PUT | articles/{article}/like | articles.like | App\Http\Controllers\ArticleController@like | web,auth | | | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web,guest | | | POST | login | | App\Http\Controllers\Auth\LoginController@login | web,guest | | | POST | logout | logout | App\Http\Controllers\Auth\LoginController@logout | web | | | GET|HEAD | password/confirm | password.confirm | App\Http\Controllers\Auth\ConfirmPasswordController@showConfirmForm | web,auth | | | POST | password/confirm | | App\Http\Controllers\Auth\ConfirmPasswordController@confirm | web,auth | | | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail | web | | | POST | password/reset | password.update | App\Http\Controllers\Auth\ResetPasswordController@reset | web | | | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web | | | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController@showResetForm | web | | | POST | register | | App\Http\Controllers\Auth\RegisterController@register | web,guest | | | GET|HEAD | register | register | App\Http\Controllers\Auth\RegisterController@showRegistrationForm | web,guest | +--------+-----------+-------------------------+------------------+------------------------------------------------------------------------+---------------------------------+
■Controller ArticleController.php
<?php namespace App\Http\Controllers; use App\Article; use Illuminate\Http\Request; use App\Http\Requests\ArticleRequest; class ArticleController extends Controller { public function __construct() { $this->authorizeResource(Article::class, 'article'); } public function index() { $articles = Article::all()->sortByDesc('created_at'); return view('articles.index', ['articles' => $articles]); } public function create() { return view('articles.create'); } }
ちなみに、それっぽい記事がありましたので、試しましたが、変わらずNotFoundです。
参考にした記事はこちら。Laravelでroutingは合ってるはずなのに404not foundが出るときにやること
■現在のhttpd.conf
# # Deny access to the entirety of your server's filesystem. You must # explicitly permit access to web content directories in other # <Directory> blocks below. # <Directory /> #AllowOverride none AllowOverride All Require all denied </Directory> # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/var/www/html" # # Relax access to content within /var/www. # <Directory "/var/www"> #AllowOverride None AllowOverride All # Allow open access: Require all granted </Directory> # Further relax access to the default document root: <Directory "/var/www/html"> Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # #AllowOverride None AllowOverride All # # Controls who can get stuff from this server. # Require all granted </Directory>
■.htaccessの内容
<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>
他、やるべきことがあればご教示いただけますと幸いです。
resources/views/articles/create.blade.php
は確かに存在していますか?
スクリーンショットを撮って質問に貼ってください。
回答2件
あなたの回答
tips
プレビュー