我正在尝试更新sprint的变量方面,以用所选sprint的任务填充表格。
这是用于选择sprint的标签:
@foreach($project->sprints as $s)
<a href="#" >{{$s->version}}</a>
@endforeach
接下来,任务表:
@php ($sprint = null)
@if($sprint != null)
<table class="table table-striped">
<thead>
<tr>
...
</tr>
</thead>
<tbody>
@foreach($sprints->tasks as $task)
<tr>
...
</tr>
@endforeach
</tbody>
</table>
@else
...
如何将$ s分配给$ sprint?
答案 0 :(得分:1)
您必须处理控制器中的选定冲刺。
假设您已定义:
路线
Route::get('/project/{projectId}', [
'uses' => 'ProjectController@show',
'as' => 'showProject'
])
控制器
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Project;
class ProjectControllerextends Controller
{
public function show(int $projectId, Request $request)
{
$project = Project::with(['sprints.tasks'])->find($projectId);
$selectedSprint = $request->query('selectedSprint')
if (!empty($selectedSprint)) {
$selectedSprint = $project->sprints->first(function($sprint) use ($selectedSprint) {
return $sprint->id === (int) $selectedSprint;
});
}
return view('projects.show', ['project' => $project, 'selectedSprint' => $selectedSprint]);
}
}
查看
@foreach($project->sprints as $s)
<a href="{{route('showProject', ['projectId' => $project->id, 'selectedSprint' => $s->id])}}">
{{$s->version}}
</a>
@endforeach
@if($selectedSprint != null)
<table class="table table-striped">
<thead>
<tr>
...
</tr>
</thead>
<tbody>
@foreach($selectedSprint->tasks as $task)
<tr>
...
</tr>
@endforeach
</tbody>
</table>
@else