두 datetimes 사이의 차이를 계산하려고합니다. tasks
많은 task_interactions
을 가지고 있으며, task_interactions
이 tasks
에 속하는 :Laravel Carbon - 데이터베이스 항목 간의 시간 계산
나는 두 가지 모델, tasks
및 task_interactions
는, 그들은 다음과 같이 관련되어 있습니다.
사용자는 작업 상태를 "진행 중", "일시 중지"및 완료 중 하나로 변경할 수 있습니다. 사용자는 '진행 중'과 '일시 중지'사이에서 상태를 여러 번 변경하지만 작업이 완료되면 더 이상 작업 상태를 변경할 수 없습니다.
모든 상호 작용은 을 user_id로, created_at
을 datetime으로 사용하여 task_interactions
테이블에 저장됩니다. 표에는 id ; task_id ; status ; comments ; created_by ; created_at
열이 있습니다.
# id, task_id, status, comments, created_by, created_at
144, 1, In Progress, , 1, 2017-11-14 09:42:20
145, 1, Paused, , 1, 2017-11-14 09:45:53
146, 1, In Progress, , 1, 2017-11-14 09:46:57
147, 1, Paused, , 1, 2017-11-14 09:49:57
148, 1, In Progress, , 1, 2017-11-14 10:00:10
149, 1, Paused, , 1, 2017-11-14 10:06:25
150, 1, In Progress, , 1, 2017-11-14 10:07:26
151, 1, Paused, , 1, 2017-11-14 10:08:11
153, 1, Paused, , 1, 2017-11-14 11:27:04
154, 1, In Progress, , 1, 2017-11-14 11:27:21
155, 1, Paused, , 1, 2017-11-14 11:57:38
것은,이다, 나는 In Progress
와 Paused
사이의 시간을 결정해야합니다. Paused
과 In Progress
사이의 시간은 적합하지 않습니다.
나는 이걸로 strugling 오전. 나를 도울 수있는 사람이 있습니까?
미리 감사드립니다.
내 질문에 약간의 멍청한 소리가 들리면, 경험이 많지 않습니다. 나는 task_id = X가있는 모든 task_interactions를 통해 @foreach
루프를 수행해야한다고 생각합니다. 내가 지금까지
@foreach ($tasks as $task)
@foreach ($task->interactions as $interactions)
{{ In here, every time my loop returns a status = "In progress" i should mark that time, and if that the next loop returns a "Paused", i should count the difference between these two. And sum all other equal cases in the loop. }}
@endforeach
@endforeach
내가 정말 수행하는 방법에 대한 아무 생각이 무엇을 알고,
public function mytasks()
{
$users = User::all();
$mytasks = Task::where('assigned_to','=', Auth::id())->where('status','!=','Finished')->get();
$mytaskscount = Task::where('assigned_to','=', Auth::id())->count();
$tasksinprogress = Task::where('status','=','In Progress')->where('assigned_to','=', Auth::id())->get();
$tasksinprogresscount = Task::where('status','=','In Progress')->where('assigned_to','=', Auth::id())->count();
$taskspaused = Task::where('status','=','Paused')->where('assigned_to','=', Auth::id())->get();
$taskspausedcount = Task::where('status','=','Paused')->where('assigned_to','=', Auth::id())->count();
$tasksfinished = Task::where('status','=','Finished')->where('assigned_to','=', Auth::id())->get();
$tasksfinishedcount = Task::where('status','=','Finished')->where('assigned_to','=', Auth::id())->count();
$tasktypes = Tasktype::all();
$chapters = Chapter::all();
return view('pages.tasks_my', compact('mytasks','tasktypes','chapters','tasksinprogress','taskspaused','tasksfinished','mytaskscount','tasksinprogresscount','taskspausedcount','tasksfinishedcount'));
}
그리고 한 가지 더 :
요청으로, 여기 내가보기를 통과하고 데이터의 그
컨트롤러를 밀 수 있습니까? –
나는이 질문에 대한 답변을 알고 싶습니다. – lewis4u
이 문제를 처리 할 수있는 db 쿼리를 개인적으로 담당합니까? PHP로 결과를 반복하는 것은 마음에 오는 것입니다. – Chay22