Мы создаем API для нашего проекта Laravel. Возвращаемая ошибка:
Попытка получить свойство необъекта
Однако данные отображаются для меня, и я думаю, что в моем запросе нет ошибок,Может кто-нибудь помочь мне с этим вопросом?
Структура базы данных
Parents and Students are in the same table it only differs from roles.
+-------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(191) | NO | | NULL | |
| fname | varchar(191) | NO | | | |
| lname | varchar(191) | NO | | | |
| email | varchar(191) | NO | UNI | NULL | |
| password | varchar(191) | NO | | NULL | |
| role | int(11) | NO | | 0 | |
| school_id | int(11) | NO | | NULL | |
| student_school_id | varchar(191) | YES | UNI | NULL | |
| student_card_no | varchar(191) | YES | UNI | NULL | |
| section_id | int(11) | YES | | NULL | |
| parent_id | int(11) | NO | | 0 | |
| gender | int(11) | NO | | 1 | |
| birthdate | date | YES | | NULL | |
| address | varchar(191) | NO | | | |
| phone | varchar(191) | YES | | NULL | |
| photo_path | varchar(191) | NO | | | |
| dependent | int(11) | NO | | 0 |
+-------------------+------------------+------+-----+---------+----------------+
Запрос
$user = Auth::user();
if($user->role != 3) {
return response()->json([
'code' => '03',
'status' => 'Invalid User',
], 403);
}
$dependent = $user->id;
// $dependent = User::find($request->student_id);
if (empty($dependent) || $dependent->$user->parent_id != $user->id)
{
return response()->json([
'code' => '04',
'status' => 'Invalid Dependent ID'
], 403);
}
/*
* Get present school year based on this day.
*/
$present_sy = Schoolyear::where('school_id', '=', $dependent)
->whereDate('from_date', '<', Carbon::now()->toDateString('Y-m-d'))
->whereDate('to_date', '>', Carbon::now()->toDateString('Y-m-d'))
->first();
Ошибка
'{"id":6,"name":"PARENT","fname":"PARENT","lname":"PARENT","email":"parent@gmail.com","role":3,"school_id":1,"student_school_id":null,"student_card_no":null,"section_id":null,"parent_id":0,"gender":1,"birthdate":null,"address":"","phone":null,"photo_path":"","dependent":0,"mobonly":0,"smsnotify":0,"appnotify":1,"is_logged":0,"confirmed":1,"confirmation_code":null,"updated_by":null,"created_at":"2019-09-27
07:37:17","updated_at":"2019-09-27 07:37:17"}' of non-object" ```