尝试获取$ user-> id来按创建者和日志过滤$ tasks给出了错误。 帮助plz
[2019-06-28 10:52:18] local.ERROR:尝试获取的属性“ id” 非对象{“ exception”:“ [对象](ErrorException(code:0):试图 在以下位置获取非对象的属性“ id” /home/vitaliy/Projects/table/app/Http/Controllers/Api/GanttController.php:30)
GanttController
public function get(){
$links = new Link();
$user = Auth::user();
$task_user = TaskUser::all()->where('user_id', $user->id);
$filter_tasks = collect();
foreach ($task_user as $task){
$get_task = Task::find($task{'task_id'});
$filter_tasks[] = $get_task;
}
return response()->json([
"data" => $filter_tasks,
"links" => $links->all()
]);
}
api.php
Route::post('/login', 'Api\Auth\LoginController@login')->name('login.login');
Route::get('/tasks/self', 'Api\TaskController@self');
Route::get('/data', 'Api\GanttController@get');
Route::resource('task', 'Api\TaskController');
Route::resource('link', 'Api\LinkController');
view.blde
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
gantt.config.xml_date = "%Y-%m-%d %H:%i:%s";
gantt.init("gantt_here");
gantt.load("/api/data");
var dp = new gantt.dataProcessor("/api");
dp.init(gantt);
dp.setTransactionMode("REST");