Why the laravel crud goes to dashboard?

Viewed 31

I am trying to create a crud app with laravel 9 and vuejs but when I run the app it goes to the dashboard and the crud operations don't appear. I want it to directly goes to the crud operations. Here is the web.app route codes:

<?php

use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use App\Http\Controllers\PostController;
/*
|--------------------------------------------------------------------------
| 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('/', 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);
1 Answers

The Route::resource function creates the routes for you with defined paths shown in the link here: https://laravel.com/docs/9.x/controllers#actions-handled-by-resource-controller

If you want to define the endpoint for going directly to posts but want to keep the rest of the default resources you can do something like this:

Route::resource('posts',PostController::class)->except(['index']);

Route::get('/dashboard',[PostController::class,'index'])->name('dashboard');

And comment out the other Dashboard link

IF you want to change the home link, you can open the RouteServiceProvider in App/Providers/RouteServiceProvider and update it there to "/posts" which would be much faster and less confusing.

    public const HOME = '/posts';
Related