| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\Api\Controllers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use App\Api\Transformers\NotificationTransformer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use App\Models\Notification; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Dingo\Api\Routing\Helpers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Illuminate\Http\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class NotificationController extends Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     use Helpers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * Display a listing of all notifications | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * @param Request $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * @param null $type archive or null (all) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @return \Illuminate\Http\Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 1 |  |     public function index(Request $request, $type = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 1 |  |         if ($type === 'archive') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 1 |  |             $notifications = Notification::isArchived($request->user())->get(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 1 |  |             $notifications = Notification::isUnread()->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 1 |  |         return $this->response->collection($notifications, NotificationTransformer::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     public function update(Request $request, $id, $action) | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         $notification = Notification::find($id); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         $enable = strpos($action, 'un') === false; | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |         if (!$enable) { | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |             $action = substr($action, 2); | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         if ($action == 'read') { | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |             $result = $notification->markRead($enable); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         } elseif ($action == 'sticky') { | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |             $result = $notification->markSticky(false); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         if ($result === false) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |             return $this->response->errorInternal(); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |             return $this->response->array(array('statusText' => 'OK')); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * Create a new notification | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @return \Illuminate\Http\Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     public function create(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $notification = new Notification; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $notification->title = $request->title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $notification->body = $request->body; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $notification->checksum = hash('sha512', $request->user()->user_id.'.LOCAL.'.$request->title); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $notification->source = $request->user()->user_id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         if ($notification->save()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             return $this->response->array(array('statusText' => 'OK')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             return $this->response->errorInternal(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 71 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |  | 
            
                        
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: