laravel - 如何使用控制器导入数据以在 Laravel 8 中查看。*
问题描述
我想从主页(索引)转到特定对象视图。这是我与即将显示的页面进行通信的方式
{{ route('object',['id'=>$object->id]) }}
错误信息:
错误消息说控制器应该有问题,但在以前的情况下,此代码有效。
web.php(路由)
Route::get('/object/{id}','FrontendController@object')->name('object');
我的前端控制器
use App\Interfaces\FrontendRepositoryInterface;
class FrontendController extends Controller
{
public function __construct(FrontendRepositoryInterface $frontendRepository)
{
$this->fR = $frontendRepository;
}
public function index()
{
$objects = $this->fR->getObjectsForMainPage();
//dd($objects);
return view('frontend.index',['objects'=>$objects]);
}
public function object($id)
{
$object = $this->fR->getObject($id);
//dd($objects);
return view('frontend.object',['object'=>$object]);
}
前端存储库
use App\Models\EventObject;
use App\Models\Photo;
use App\Interfaces\FrontendRepositoryInterface;
class FrontendRepository implements FrontendRepositoryInterface {
public function getObjectsForMainPage()
{
return EventObject::with(['photos','clubs'])->get();
}
public function getObject($id)
{
return EventObject::with(['photos','clubs'])->get();
}
}
解决方案
解决方案是使用 php artisan route:cache 清除路由缓存并在路由中添加丢失的 /
Route::get('/object/'.'{id}','FrontendController@object')->name('object');
推荐阅读
- typescript - Firestore - 如何从 FirebaseFirestore.QuerySnapshot 获取文档 ID?
- java - 未创建表,在 Spring Boot 的多个应用程序中使用来自 maven jar 依赖项的实体
- apache - Apache Nifi:UpdateRecord 替换子值
- android - Android Room:存储对象层次结构并查询超类
- git - Git: Is it possible to rename master?
- python - 从模块访问变量
- regression - 使用 libreOffice calc 通过一组 3D 点拟合平面,以最小化总距离
- css - 如何为具有自定义列宽的可滚动表完成固定标题?
- docker - 如何通过将自定义补丁应用到文件而不具有状态“已退出 (0)”来创建自定义 Docker 映像
- tensorflow - TensorFlow 2.0 使用 GradientTape 在 dtype=int32 上返回意外输出