如果一个项目中有多项费用,我如何将它们加在一起并成为一行?
If there are multiple expenses in a project, how can I sum them together and make a single row?
I have two table as you can see that relations each other.
I want to see this table
如何在我的 blade 文件或控制器中执行此操作。
这是我的 blade 文件;
@foreach ($costs as $cost)
@foreach ($projects as $project)
@if($project->id == $cost->project_id)
<tr class="odd">
<td>{{ $project->id }}</td>
<td>{{ $cost->price }}</td>
</tr>
@endif
@endforeach
@endforeach
public function tablo1()
{
$costs = DB::table('cost_manages')
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('projects')
->whereColumn('projects.id', 'cost_manages.project_id')->groupBy('project_id');
})
->get();
$projects = DB::table('projects')
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('cost_manages')
->whereColumn('cost_manages.project_id', 'projects.id');
})
->get();
return view('home.muhasebe_Tablo1', [
'costs' => $costs,
'projects' => $projects
]);
}
那个是我的控制器。
项目编号 11 有 2 个成本。我想通过收集它们来写一个记录。
请帮助我
使用连接:
DB::table('projects')
->leftjoin('cost_manages', 'projects.id','const_manages.project_id')
->select('projects.id as id', 'projects.name as name', 'cost_manages.cost as cost')->get()
然后遍历这个。
I have two table as you can see that relations each other.
I want to see this table
如何在我的 blade 文件或控制器中执行此操作。
这是我的 blade 文件;
@foreach ($costs as $cost)
@foreach ($projects as $project)
@if($project->id == $cost->project_id)
<tr class="odd">
<td>{{ $project->id }}</td>
<td>{{ $cost->price }}</td>
</tr>
@endif
@endforeach
@endforeach
public function tablo1()
{
$costs = DB::table('cost_manages')
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('projects')
->whereColumn('projects.id', 'cost_manages.project_id')->groupBy('project_id');
})
->get();
$projects = DB::table('projects')
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('cost_manages')
->whereColumn('cost_manages.project_id', 'projects.id');
})
->get();
return view('home.muhasebe_Tablo1', [
'costs' => $costs,
'projects' => $projects
]);
}
那个是我的控制器。 项目编号 11 有 2 个成本。我想通过收集它们来写一个记录。 请帮助我
使用连接:
DB::table('projects')
->leftjoin('cost_manages', 'projects.id','const_manages.project_id')
->select('projects.id as id', 'projects.name as name', 'cost_manages.cost as cost')->get()
然后遍历这个。