【发布时间】:2021-03-24 10:38:20
【问题描述】:
我正在尝试使用资源路由创建一个 crud 应用程序,但我的索引方法没有返回任何视图 使用路线http://127.0.0.1:8000/admin/index
路由文件
Route::resource("admin","StudentController");
控制器
public function index(){return view("welcome");}
【问题讨论】:
我正在尝试使用资源路由创建一个 crud 应用程序,但我的索引方法没有返回任何视图 使用路线http://127.0.0.1:8000/admin/index
路由文件
Route::resource("admin","StudentController");
控制器
public function index(){return view("welcome");}
【问题讨论】:
Laravel 路由系统在 Laravel 8.x 中略有改变,现在需要控制器的全限定类名:
Route::resource('admin', 'App\Http\Controllers\StudentController');
【讨论】:
您没有访问index 路由。您使用的 URI http://127.0.0.1:8000/admin/index 用于 show 路由而不是 index。 index 路由将是 http://127.0.0.1:8000/admin/ 。
很可能您的控制器的show 方法没有返回任何内容,因此它是一个空白页面。
【讨论】:
Route::resource("admin","App\Http\Controllers\StudentController");
public function index(){return view("welcome");}
http://127.0.0.1:8000/admin
【讨论】:
试试这个 当您使用资源方法时,索引和创建函数使用相同的 url,但方法不同,例如索引使用 get 和 create 使用 post 那就试试这个http://127.0.0.1:8000/admin
【讨论】: