我得到错误404当应用路由模型绑定时,我不明白哪里出错,即使我检查路由和控制器是正确的
这是我的索引编码
x一a0b1x x一a1b1x
我的路线代码
<?php
use App\Http\Controllers\HomepageController;
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::get('/', [HomepageController::class, 'index']);
Route::get('/{buku:slug}', [HomepageController::class, 'show']);
Route::get('/{kategori:slug_kategori}', [HomepageController::class, 'lihat']);
我的控制器代码
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Buku;
use App\Models\Kategori;
class HomepageController extends Controller
{
public function index() {
return view('homepage/index',[
"title" => "Homepage",
"books" => Buku::all(),
"kategori" => Kategori::all(),
]);
}
public function show(Buku $buku) {
return view('homepage/lihat', [
'title' => 'Detail Buku',
'book' => $buku
]);
}
public function lihat(Kategori $kategori) {
return view('homepage/kategori', [
'title' => $kategori->nama,
'kategoris' => $kategori,
]);
}
}
卡捷戈里迁移
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('kategoris', function (Blueprint $table) {
$table->id();
$table->string('kode_kategori')->unique();
$table->string('nama_kategori')->unique();
$table->string('slug_kategori');
$table->text('deskripsi_kategori');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('kategoris');
}
};
和文件视图结构file views structure
我得到错误404当应用路由模型绑定时,我不明白哪里出错,即使我检查路由和控制器是正确的
2条答案
按热度按时间icomxhvb1#
请尝试以下artisan命令
php工匠配置:清除
php工艺路线:透明
5f0d552i2#
显示404页面的路由是什么?,也许是该高速缓存原因,请尝试以下命令: