title: How to know if a specific notification has been sent in laravel
body: <p>I am building a site where users can buy a plan for whatever estimated time they require. After they buy the plan I created a middleware to check when the plan is almost finished (70% into the plan) then send a notification . Now the issue is I am trying to find out if the Notification in question has already been sent before sending another notification. I used database notification method. </p>
  
  <p>To achieve this I had to create a Notification model to interact with my notification table. </p>
  
  <pre><code>    &lt;?php
  
      namespace App;
  
      use Illuminate\Database\Eloquent\Model;
  
      class Notification extends Model
      {
          protected $table= "notifications"; 
      }
  </code></pre>
  
  <blockquote>
    <p>The middle ware in question</p>
  </blockquote>
  
  <pre><code> public function handle($request, Closure $next)
      {
         // dd(Carbon::now()-&gt;format("Y-m-d"));
         $plan = Booking::where("user_id", Auth::id())
                          -&gt;where("approve", true)
                          -&gt;where("end_date", '&gt;', Carbon::now()-&gt;format("Y-m-d"))
                          -&gt;get();
          $i =0;
          $save = [];
  
          foreach($plan as $plan){
  
             $save[$i] = (new Plan)-&gt;percentageMeter($plan-&gt;start_date, $plan-&gt;end_date);
             if($save[$i] &gt;= 70){
  
                  $realNotify= Notification::where("notifiable_id", $plan-&gt;user_id)
                                      -&gt;get();
                  foreach($realNotify as $notify){
  
                      if($notify-&gt;data['plan_id'] == $plan-&gt;id &amp;&amp; realNotify ==true ){
                          continue;
  
                      }
                      else{
  
                          ComNotify::planAboutToExpire(Booking::find($plan-&gt;id));
  
                      }
                  }
  
  
  
                 continue;
  
             }
  
             $i++;
          }
      // dd($save);
  
      }
  </code></pre>
  
  <p>one of the major reason I have this problem is that I cant access the "plan_id" object because it does not have its own table column. </p>
  
  <p>Is there a Laravel way to do this? a neat way. </p>
  
  <pre><code>public function toArray($notifiable)
      {
          return [
              "type"=&gt;"plan_about_to_expire",
              "message"=&gt;"Your plan will soon expire on " . $this-&gt;plan-&gt;end_date,
              "plan_id"=&gt;$this-&gt;plan-&gt;id,
  
  
          ];
      }
  </code></pre>
  
  <p><strong>My notification toArray method</strong></p>