vendredi 29 juillet 2016

Laravel Inserts extrea rows before downloading a file

Before downloading a file by user I want to log it in the database that user downloaded which file, so I implemented this function below:

  public function downloadTheme(Theme_lang $themLang)
{

    $userOrdered=$this->getUserOrdered();

   if(($themLang->is_free==1) || (in_array($themLang->id,$userOrdered))){
        Theme_download::create(['user_id'=>Auth::user()->id,'theme_lang_id'=>$themLang->id]);
        $file=base_path($themLang->download_url);
        return response()->download($file);
   }else{...}
}

But the problem is when I check the database I see there are extra duplicated rows inserted there! So how can I solve it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire