dimanche 2 décembre 2018

How to broadcast a message in Laravel

I'm trying to broadcast a message or a notification to all the users after the store function of my controller is successfull.

public function store(Request $request,$id)
   {
      if(Auth::check()){

          $permit = Permit::where('id',$id)->first();
          if ($permit)
           {
             $request->validate([
                 'invoice_no' => 'required|string|max:255',    
             ]);

             $invoice = Invoice::insert([
                'invoice_no' => $request->input('invoice_no'),  
                'invoice_date' => $request->input('invoice_date'),  
                'permit_id' => $permit->id,    
                'created_at' => Carbon::now(),                    
             ]);

             if($invoice){
                $permit->invoiced = 1;
                $permit->save();
                $users = User::where('user_type','superadmin')->get();
                $message = "Permit number ".$permit->permit_no." invoiced successful!";
                foreach ($users as $user) {

                    // Need to implement a method here to notify all users

                }
                return redirect()->route('invoices.index')
                    ->with('success' , 'successFull');
             }
         }
         return back()->withInput()->with('errors', 'Error Exists!');
     }
  }

So $message is the message I'm trying to notify all users.

I want to use something like bootstrap-notify package to show the message. How can this be achieved? I had done some tutorials but it uses Vue.js and I dont want to jump into Vue.js for now. So any other solutions please reply.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2BMP96J
via IFTTT

Aucun commentaire:

Enregistrer un commentaire