Reputation: 49
Recently I am working on a project 'facebook-clone' using Laravel and vue.js. I have been using unit test for the first time. After performing the test I found this error,
Error: "ErrorException: Trying to get property 'id' of non-object"
For sending a friend request I wrote this
test.a_user_can_send_a_friend_request
I am using many to many relationships in User Model.
many to many relationships within users model
this is the pivot table friends
Api route:
api.php
The Controller used:
FriendRequestController
The resource used:
Friend
Upvotes: 0
Views: 743
Reputation: 49
The problem is solved, I made a mistake in FriendRequestController where I should have passed an argument in Friendesource, instead I passed an array by mistake.
With error:
return new FriendResource([
Friend::where('user_id', auth()->user()
->id)->where('friend_id', $data['friend_id'])
->first()
]);
after fixing error:
return new FriendResource(
Friend::where('user_id', auth()->user()
->id)->where('friend_id', $data['friend_id'])
->first()
);
Upvotes: 0