Home  >  Q&A  >  body text

Laravel routing took me into unknown territory

I'm trying to create a CRUD application using Laravel and vue.js, but I keep running into problems. When I run the application it goes to the dashboard but the CRUD operations don't show up. The following is the Routes/web.app code:

<?php

use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use App\Http\Controllers\PostController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| 这里是您可以为应用程序注册Web路由的地方,这些路由由RouteServiceProvider在一个包含“web”中间件组中加载。现在创建一些伟大的东西!
|
*/
Route::get('/', function () {
    return Inertia::render('Welcome', [
        'canLogin' => Route::has('login'),
        'canRegister' => Route::has('register'),
        'laravelVersion' => Application::VERSION,
        'phpVersion' => PHP_VERSION,
    ]);
});
Route::get('/dashboard', function () {
    return Inertia::render('Dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');

require __DIR__.'/auth.php';

Route::resource('Posts', PostController::class);
P粉557957970P粉557957970225 days ago484

reply all(1)I'll reply

  • P粉877719694

    P粉8777196942024-04-01 00:23:05

    I think I get it, you will be logged in before so when you try to run your app it will take you to the dashboard.

    solution: You should make sure to clear all cache/session data and then run php artisan serve,

    Hopefully now it will take you to the / => Welcome page!

    (If not) You need to check the following points:

    1. Your controller is not protected by any middleware (in the constructor).
    2. You are not logged in as a verified user, you can try in the incognito mode of Google Chrome. If http://localhost:8000 displays your welcome page, then visit the http://localhost:8000/posts route (first change Route::resource('Posts', PostController::class); to Route:: resource('/posts', PostController::class);)
    3. Runphp artisan optimize:clear

    reply
    0
  • Cancelreply