本文整理汇总了PHP中app\Task::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Task::with方法的具体用法?PHP Task::with怎么用?PHP Task::with使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Task
的用法示例。
在下文中一共展示了Task::with方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: demo_efficient_eager_loading_eloquent_relationship_query
/** @test */
public function demo_efficient_eager_loading_eloquent_relationship_query(FunctionalTester $I)
{
// given ... 3 tasks, each belonging to a user
// when ... we get tasks "with" their user
// it would result in only 2 SQL queries in total (which is efficient)
$tasks = Task::with('user')->get();
// then ... should return all tasks with their user
$I->assertSame(3, count($tasks));
$I->assertSame("Sherlock Holmes", $tasks[0]->user['name']);
// task 1
$I->assertSame("Sherlock Holmes", $tasks[1]->user['name']);
// task 2
$I->assertSame("Dr Watson", $tasks[2]->user['name']);
// task 3
}
示例2: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$issues = Issue::with('company', 'company.person')->has('task', '<', 1)->get();
foreach ($issues as $issue) {
$task = new Task();
$task->issue_id = $issue->id;
$task->person_id = $issue->company->person->id;
$task->priority = $issue->level * $issue->company->score;
$task->save();
}
$tasks = Task::with('issue', 'issue.company', 'person')->orderBy('priority', 'DESC')->get();
echo 'ID | Name | Company | Priority | Assigned Person', PHP_EOL;
foreach ($tasks as $task) {
echo sprintf('%d | %s | %s | %d | %s', $task->id, $task->issue->name, $task->issue->company->name, $task->priority, $task->person->name), PHP_EOL;
}
}
示例3: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//$tasks = Task::take(100)->get();
//$tasks = Task::with('assignees')->get();
// TODO MAKE SURE YOU CAN'T DUPLICATE ASSIGNEES
$tasks = Task::with(['assignees' => function ($query) {
// Puts the current user first in the array of assignees
$query->orderByRaw('id = ? DESC', Auth::user()->id);
}, 'tags'])->get();
// DB::table('users')->chunk(100, function($users) {
// foreach ($users as $user) {
// //
// }
// });
$users = User::all();
$tags = Tag::all();
return view('tasks/tasks')->with(array('tasks' => $tasks, 'users' => $users, 'tags' => $tags));
}
示例4: get
/**
* GET /api/dashboard
*
* @param $userId
* @param $partnerId
* @param Request $request
*
* @return
*/
public function get($userId, $partnerId, Request $request)
{
// Get current room
$room = $request->room;
$progressions = Progression::where('room_id', '=', $room->id)->get();
$tasksIds = [];
$tasks = [];
// Get all tasks use in the room
foreach ($progressions as $value) {
if (!in_array($value->task_id, $tasksIds)) {
$tasksIds[] = $value->task_id;
$task = Task::with('category')->where('id', '=', $value->task_id)->first();
$userProgression = Progression::where('room_id', '=', $room->id)->where('user_id', '=', $userId)->where('task_id', '=', $task->id)->first(['count']);
$partnerProgression = Progression::where('room_id', '=', $room->id)->where('user_id', '=', $partnerId)->where('task_id', '=', $task->id)->first(['count']);
$tasks[] = ['id' => $task->id, 'category' => $task->category, 'name' => $task->name, 'difference' => $userProgression->count - $partnerProgression->count];
}
}
// Return response
return Response::json(['status_code' => 200, 'tasks' => $tasks]);
}
示例5: taskexcel
public function taskexcel($id)
{
Excel::create('Excel ', function ($excel) use($id) {
$excel->sheet('new Sheet', function ($sheet) use($id) {
$taskforms = TaskForm::where('task_id', $id)->with('device')->get();
$task = Task::with('company')->find($id);
$sheet->setAllBorders('thin');
$sheet->setStyle(array('font' => array('name' => 'Calibri', 'size' => 10, 'bold' => false)));
// Set border for cells
$sheet->loadView('report.taskexcel')->with('taskforms', $taskforms)->with('task', $task);
});
})->download('xls');
}
示例6: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
return Task::with('tasklist')->findOrFail($id)->toJson();
}
示例7: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
return response()->json(Task::with('user', 'category')->get());
}
示例8: forUser
/**
* @param User $user
* @return App\Task[]
*/
public function forUser(User $user)
{
// return $user->tasks()->getResults();
return Task::with('user')->withTrashed()->where('user_id', $user->id)->orderBy('created_at', 'asc')->get();
}
示例9: history
/**
* History page
*/
public function history()
{
//get timezone offset for scoreboard
$offset = new DateTime('now', new DateTimeZone(Auth::user()->timezone));
$time = time() + $offset->getOffset();
//get last six days' totals
$days = $weeks = [];
for ($i = 0; $i < 6; $i++) {
$day = $time - 60 * 60 * 24 * $i;
$end = $time - 60 * 60 * 24 * 7 * $i;
$start = $time - 60 * 60 * 24 * 7 * ($i + 1) + 60 * 60 * 24;
$weeks[date('M j', $start) . '–' . date('M j', $end)] = Task::where('closed_at', '>=', date('Y-m-d', $start))->where('closed_at', '<=', date('Y-m-d', $end))->sum('hours');
$days[date('l', $day)] = Task::where('closed_at', date('Y-m-d', $day))->sum('hours');
}
//$days = array_reverse($days);
//dd($weeks);
//get tasks
$tasks = Task::with('project')->whereNotNull('closed_at')->orderBy('closed_at', 'desc')->orderBy('updated_at', 'desc')->paginate(20);
return view('task.history', compact('days', 'weeks', 'tasks'));
}
示例10: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
$tasks = Task::with('company', 'step', 'category', 'log')->where('step_id', '<', 7)->get();
return view('task.list', compact('tasks'));
}
示例11: index
public function index()
{
//
$tasks = Task::with(['company', 'step'])->orderBy('created_at', 'DESC')->get();
return view('task.index', compact('tasks'));
}
示例12: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show(Task $task, TaskRequest $request)
{
Log::info("[App\\TaskController]: Get a Task");
$task = Task::with('priority', 'tags')->where('id', $task->id)->first();
return response()->json($task);
}
示例13: apitasks
public function apitasks()
{
$tasks = Task::with('owner', 'assigned')->get();
return $tasks;
}
示例14: index
/**
* @return \Symfony\Component\HttpFoundation\Response
*
* List all available tasks and output in json
*/
public function index()
{
$Tasks = Task::with('task_done')->get();
return response()->json($Tasks);
}