0
我想知道從某個項目中的所有衝刺中選擇所有可交付成果的最有效方法是什麼。在我只查詢它們並使用blade.php進行循環以及if語句來篩選我需要的交付物之前,什麼是最有效的方式在PHP執行此任務?Laravel與多個父ID的查詢
衝刺控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Requests\SprintRequest;
use Reponse;
use App\Sprint;
use App\Deliverable;
use App\Project;
class SprintController extends Controller
{
private function __construct(){
$this->middleware('role:admin', ['except' => ['index', 'show']]);
}
public function index($project_id)
{
$project = Project::findOrFail($project_id);
$sprints = $project->sprints()->get();
$deliverables = array();
foreach ($sprints as $sprint) {
array_push($deliverables, $sprint->deliverables()->get());
}
$amount = 0;
$completed = 0;
foreach ($deliverables as $deliverable) {
if ($deliverable->complete == '1' && $deliverable->sprint_id == $sprint->id && $deliverable->inactive == '0') {
$completed += 1;
$amount += 1;
}
else if ($deliverable->sprint_id == $sprint->id && $deliverable->inactive == '0') {
$amount += 1;
}
}
return view('sprints.index', compact('sprints', 'deliverables', 'amount', 'completed', 'project'));
}
public function create($project_id)
{
$project = Project::findOrFail($project_id);
$sprint = new Sprint;
return view('sprints.create', compact('project', 'sprint'));
}
public function store(SprintRequest $request, $project_id)
{
$project = Project::findOrFail($project_id);
$sprint = new Sprint;
$sprint->name = $request->name;
$project->sprints()->save($sprint);
return "success";
}
public function edit($project_id, $sprint_id)
{
$project = Project::findOrFail($project_id);
$sprint = $project->sprints()->findOrFail($sprint_id);
return view('sprints.edit', compact('project', 'sprint'));
}
public function update(SprintRequest $request, $project_id, $sprint_id)
{
$project = Project::findOrFail($project_id);
$sprint = $project->sprints()->findOrFail($sprint_id);
$sprint->name = $request->name;
$sprint->save();
return "success";
}
}
這是我迄今爲止,但它給了我這個錯誤
BindingResolutionException在Container.php行748: 目標[應用程序\ HTTP \控制器\ SprintController]不可實例化。
感謝
顯示SprintController代碼 –
您將在刀片中過濾什麼? – EddyTheDove
Shoudn't急切的負載交付物? –