jeudi 19 décembre 2019

How to remove or unfriend through API

This is database structure enter image description here This is API

Route::post('/friend', 'FriendController@index');
Route::post('/removerequest/{id}', 'FriendController@removerequest');

This is controller code which into friend request method and remove method, but error in remove friend method..

 public function index(Request $request) {
       
        $sender = Friend::where('sender_id', $request->sender_id)->where('receiver_id',$request->receiver_id)->first();
        if(empty($sender)){
            Friend::create(['sender_id'=>$request->sender_id,'receiver_id'=>$request->receiver_id, 'approved'=>'pending']);
            
            $response = ['message'=>'Friend Request has been sent','status'=>200];
            return response()->json($response);
        }else{
            $response = ['message'=>'Request has been sent already','status'=>200];
            return response()->json($response);
        }
        
    }
    public function removerequest($id){
       $friends = Friend::all()
                    ->where('receiver_id')
                    ->where('sender_id')
                    ->approved('accept')
                    ->delete();
            
    }

Error is

BadMethodCallException: Method Illuminate\Database\Eloquent\Collection::approved does not exist. in file /home/ynvih0l26evc/public_html/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php on line 104
enter code here


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire