laravel初心者です。
よろしくお願いします。
初歩的な質問で申し訳ないですが、
resources/views/drink/index.blade.phpが存在するのに
laravelの404エラー画面がでます。
(なんか変なところでつまづいている気がします、、、)
##追記
やはりルーティングはあってるような気がします。
下記ソースでhttp://localhostにアクセスしても404になってます。
##ソース
#web.php <?php declare(strict_types=1); use App\Http\Controllers; use Illuminate\Routing\Router; 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::prefix('drinks')->name('drink.')->group( function (Router $router) { $router->get('/', [Controllers\DrinkController::class, 'index'])->name('index'); $router->post('/buy/{id}', [Controllers\DrinkController::class, 'buy'])->name('buy'); } );
#Controllers\DrinkController <?php declare(strict_types=1); namespace App\Http\Controllers; use App\Exceptions\Drink\Buy\GuiltyException; use App\Exceptions\Drink\Buy\NoStockException; use App\Exceptions\Drink\Buy\NotEnoughMoneyException; use App\Exceptions\Drink\NotFoundException; use App\Services\Drink\DrinkService; use Illuminate\Contracts\View\View; use Illuminate\Http\Request; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class DrinkController extends Controller { private DrinkService $service; public function __construct() { $this->service = new DrinkService(); } public function index(Request $request): View { $user = $request->user('mock'); $drinks = $this->service->list(); return view('drink.index', compact('user', 'drinks')); } }
#.env APP_URL=http://localhost
回答1件
あなたの回答
tips
プレビュー