Laravel-参数重定向选择相同的数据

时间:2019-07-01 07:03:13

标签: laravel eloquent

我想使用参数从一个视图重定向到另一个视图。显示的数据将基于所选参数。

来源

控制器

    public function revenueReport(Request $request)
{

$revenues = DB::table("vw_revenue_report")
->select(
    "vw_revenue_report.channel",
    DB::raw("SUM(CASE WHEN created_at = NOW() - INTERVAL 1 DAY THEN amount ELSE 0 END) daily_revenue"),    
    DB::raw("SUM(CASE WHEN created_at >= NOW() - INTERVAL 1 WEEK THEN amount ELSE 0 END) weekly_revenue"),
    DB::raw("SUM(CASE WHEN created_at >= NOW() - INTERVAL 1 MONTH THEN amount ELSE 0 END) monthly_revenue"),
    DB::raw("SUM(CASE WHEN created_at >= NOW() - INTERVAL 1 YEAR THEN amount ELSE 0 END) yearly_revenue"),
    DB::raw("SUM(vw_revenue_report.amount) total_revenue")
)
->groupBy("vw_revenue_report.channel")
->orderByRaw('vw_revenue_report.channel ASC')
    ->get();          

    return view('report.revenueReport');    
}  

查看

        @foreach($revenues as $key => $revenue)
        <tr>
            <td>{{ ++$key }}</td>
            <td>{{ $revenue->channel }}</td>               
            <td>{{ $revenue->daily_revenue }}</td>
            <td>{{ $revenue->weekly_revenue }}</td>
            <td>{{ $revenue->monthly_revenue }}</td>
            <td>{{ $revenue->yearly_revenue }}</td>
            <td>{{ $revenue->total_revenue }}</td>
            <td><a class="btn btn-info" href="{{ route('revenueDetail',$revenue->channel) }}">Details</a></td>
        </tr>          
    @endforeach

目的地

public function revenueDetail(Request $request, $channel = null)
{

    $revenuedetails = DB::table('vw_revenue_report as g')
    ->select(
       DB::raw('DATE(g.created_at) as created_date'),
       'g.msisdn', 
       'g.channel', 
       'g.amount'              
  )
 ->whereRaw('g.channel', $channel ?? null)
 ->orderByRaw('g.created_at DESC') 

->get();
return view('report.revenueDetail');        
}
  

参数   是$ channel

我遇到的问题是,当我单击每一行的“详细信息”时,它会将我重定向到同一组数据。

1 个答案:

答案 0 :(得分:0)

请查看Laravel documentation的视图。

代码示例:

return view('report.revenueReport', ['revenues' => $revenues]);

要使用参数路由,请查看this文档。

代码示例:

Route::get('/report/revenue-detail/{channel}', ['as' => 'revenueDetail', 'uses' => 'ReportController@revenueDetail']);