【问题标题】:Laravel Path With Different Views不同视图的 Laravel 路径
【发布时间】:2019-01-27 23:43:48
【问题描述】:

这是我的路线

Route::get('sites/{site_id}/report/{report_id}', array('as'=>'Reports'), 
function($site_id, $report_id){

// $report = ???

return view('reports')->with('report', $report)->with('site_id',$site_id)- 
>with('report_id', $report_id);

});

这是我的刀片文件

<a href="{{route('Reports',['site_id'=>$report->site_id, 
'report_id'=>$report- >report_id])}}">view</a>

这就是问题所在。我想为每个报告制定路径。示例是在此路径内有 3 个报告 http://localhost:8000/sites/1

然后,当我单击其中一个报告时,它应该给我这条路径 http://localhost:8000/sites/1/report/1 (sites/$site_id/report/$report_id)

但是当你点击report_id = 1和report_id = 2时,我很困惑 `return view('reports') 的值仍然相同,我如何为我拥有的每份报告制作不同的视图。

你有什么想法吗?

【问题讨论】:

  • 您好,如果您的解释有更好的标点/语法/段落,会更容易理解/回答。另外,我在您的代码中没有看到 for 循环?
  • 对不起,我的语法不好,我不习惯,我正在努力,我的英语不太好。
  • 没问题,试着缩短你的句子,使用句号,把想法分成几段。你不需要精通英语就可以做到这一点。
  • @Andrew 已被编辑。
  • 看起来您需要获取报告或站点,然后将其传递给刀片文件? $report = Report::find($report_id); 之类的东西?

标签: laravel


【解决方案1】:

您需要从数据库中获取信息。您可以使用您的App\Report 模型来获取报告信息:

Route::get('sites/{site_id}/report/{report_id}', ['as' => 'Reports'], function ($site_id, $report_id) {

    $report = App\Report::findOrFail($report_id);

    return view('reports')->with('report', $report)->with('site_id', $site_id)->with('report_id', $report_id);
});

您可以在documentation找到更多信息

【讨论】:

  • 我的 site_id 和 report_id 仍然为空,之前尝试过但输出相同。
猜你喜欢
  • 2017-01-06
  • 1970-01-01
  • 2016-02-09
  • 2018-03-23
  • 2010-11-13
  • 1970-01-01
  • 2015-11-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多