我是 Laravel 的新手,但是当我在 vscode 中编码时一切正常,现在当我将它上传到像 Hostinger 这样的共享服务器时它不起作用它说控制器不存在 ...我使用的是 laravel 11,我的 php 是 8.2,composer 是 2
我以为它是名称空间,但 id 看起来不像......有什么帮助吗?
我尝试了一切,从更改字母和控制器到写入权限,甚至询问人工智能但一无所获
web.php
<?php
use App\Http\Controllers\Admin\AdminController;
use App\Http\Controllers\Admin\CategoryController;
use App\Http\Controllers\Admin\MeniuController;
use App\Http\Controllers\Admin\TableController;
use App\Http\Controllers\Admin\UzsakymasController;
use App\Http\Controllers\Auth\RegisteredUserController;
use App\Http\Controllers\Frontend\CategoryController as FrontendCategoryController;
use App\Http\Controllers\Frontend\MeniuController as FrontendMeniuController;
use App\Http\Controllers\Frontend\TableController as FrontendTableController;
use App\Http\Controllers\Frontend\WelcomeController;
use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route;
use App\Http\Middleware\Admin;
// Frontend routes
Route::get('/', [WelcomeController::class, 'index']);
Route::get('/categories', [FrontendCategoryController::class, 'index'])->name('categories.index');
Route::get('/categories/{category}', [FrontendCategoryController::class, 'show'])->name('categories.show');
Route::get('/menius', [FrontendMeniuController::class, 'index'])->name('menius.index');
Route::get('/menius/{meniu}', [FrontendMeniuController::class, 'show'])->name('menius.show');
Route::get('/table', [FrontendTableController::class, 'index'])->name('table.index');
Route::get('/dashboard', function () {
return view('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');
// Authenticated user routes
Route::middleware('auth')->group(function () {
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});
// Admin routes
Route::middleware(['auth', Admin::class])->prefix('admin')->name('admin.')->group(function () {
Route::get('/', [AdminController::class, 'index'])->name('index');
Route::get('/register', [RegisteredUserController::class, 'create'])->name('register');
Route::post('/register', [RegisteredUserController::class, 'store']);
Route::resource('categories', CategoryController::class)->names([
'index' => 'categories.index',
'create' => 'categories.create',
'store' => 'categories.store',
'show' => 'categories.show',
'edit' => 'categories.edit',
'update' => 'categories.update',
'destroy' => 'categories.destroy',
]);
Route::resource('menius', MeniuController::class)->names([
'index' => 'menius.index',
'create' => 'menius.create',
'store' => 'menius.store',
'show' => 'menius.show',
'edit' => 'menius.edit',
'update' => 'menius.update',
'destroy' => 'menius.destroy',
]);
Route::resource('table', TableController::class)->names([
'index' => 'table.index',
'create' => 'table.create',
'store' => 'table.store',
'show' => 'table.show',
'edit' => 'table.edit',
'update' => 'table.update',
'destroy' => 'table.destroy',
]);
Route::resource('uzsakymas', UzsakymasController::class)->names([
'index' => 'uzsakymas.index',
'create' => 'uzsakymas.create',
'store' => 'uzsakymas.store',
'show' => 'uzsakymas.show',
'edit' => 'uzsakymas.edit',
'update' => 'uzsakymas.update',
'destroy' => 'uzsakymas.destroy',
]);
});
require __DIR__.'/auth.php';
像我的 WelcomeController.php
<?php
namespace App\Http\Controllers\FrontEnd;
use App\Http\Controllers\Controller;
use App\Models\Category;
use App\Models\Meniu;
use Illuminate\Http\Request;
class WelcomeController extends Controller
{
public function index()
{
$savaite = Category::where('name', 'Pirma savaite')->first();
return view('welcome', compact('savaite'));
}
}
改变
namespace App\Http\Controllers\FrontEnd;
到
namespace App\Http\Controllers\Frontend;
在你的WelcomeController.php上