php - Laravel 5 groupBy on collection -


i trying group tasks due date display in list.

wednesday 1 january 2015 task 1 task 2

etc

here function:

public function index() {     $user = auth::user();     $tasks = $user->tasks()->orderby('due_at','asc')->get();         $tasks_group = $tasks->groupby('due_at');        return view('tasks.index', compact('tasks_group')); } 

but receiving error:

array_key_exists(): first argument should either string or integer

i have tried few other ways returning 1 task per date.

any on doing wrong here great.

you need eager load tasks relationship groupby.

try following codes:

$user = auth::user();  $user->load(['tasks' => function ($q) {     $q->orderby('due_at', 'asc'); }]);  $tasks_group = $user->tasks->groupby('due_at');  return view('tasks.index', compact('tasks_group')); 

Comments

Popular posts from this blog

r - how do you merge two data frames the best way? -

How to debug "expected android.widget.TextView but found java.lang.string" in Android? -

php - mySQL problems with this code? -