如何在laravel 5上按id查看数据?

rkue9o1l  于 2023-01-21  发布在  其他
关注(0)|答案(3)|浏览(113)

我有一些问题在这里。我想查看所有数据排序由"kelompok"。

  • kelompok平均值组

这是密码:

    • 主计长**
public function pengelompokan()
{
    $view = DB::table('tb_siswa')->where('id', $kelompok)->get();
    return view('pengelompokan')
    ->with('view', $view);
}
    • 路线**
Route::get('kelompok', 'belajarController@kelompok');
ef1yzkbh

ef1yzkbh1#

可以使用groupBy收集方法:

$view = DB::table('tb_siswa')
    ->where('id', $kelompok)
    ->get()
    ->groupBy('kelompok');
    • 编辑**

根据您的注解,您可以执行以下操作:

Route::get('kelompok/{groupId}', 'belajarController@kelompok');

public function pengelompokan($kelompok)
{
    $view = DB::table('tb_siswa')
      ->where('id', $kelompok)
      ->get()
      ->groupBy('kelompok');

    return view('pengelompokan', compact('view'));
}
wgxvkvu9

wgxvkvu92#

下面是解决此问题的代码

public function pengelompokan()
{
    $view = DB::table('tb_siswa')->where('id', $kelompok)
            ->groupBy('kelompok')->get();
    return view('pengelompokan')->with('view');
}

您也可以在刀片上使用变量$view访问groupBy数据。

k10s72fa

k10s72fa3#

我使用的是路由,但您可以在Controller@show上应用它

Route::get('tutorial/{id}', function($id){
$tutorial = Tutorial::findOrFail($id);
return view('tutorial.show')->with('tutorial', $tutorial);})->name('show-tutorial');

并检查您的show.blade.php

相关问题