public static function boot()
 {
     parent::boot();
     CourseGalleryItem::deleting(function ($courseGalleryItem) {
         File::delete($courseGalleryItem->image);
     });
 }
 /**
  * @param Request $request
  * @param $course
  */
 private function saveCourse(Request $request, $course)
 {
     $course->fill($request->input());
     $productTags = $request->input('product_tags');
     $productTagsIds = [];
     if ($productTags) {
         foreach ($productTags as $productTag) {
             $productTagDb = ProductTag::where('name', $productTag)->first();
             if ($productTagDb == null) {
                 $productTagDb = ProductTag::create(['name' => $productTag]);
             }
             array_push($productTagsIds, $productTagDb->id);
         }
     }
     $course->save();
     $course->productTags()->sync($productTagsIds);
     $courseGalleryItemIds = [];
     if ($request->input('course-gallery-item-id') != null) {
         foreach ($request->input('course-gallery-item-id') as $key => $courseGalleryItemId) {
             $courseGalleryItem = CourseGalleryItem::findOrNew($courseGalleryItemId);
             $courseGalleryItemImageFile = $request->file('course-gallery-item-image')[$key];
             if ($courseGalleryItemImageFile != null) {
                 $courseGalleryItemImageFileName = str_random(32) . '.' . $courseGalleryItemImageFile->getClientOriginalExtension();
                 $courseGalleryItemImageFile->move(public_path() . '/img/uploads/', $courseGalleryItemImageFileName);
                 $courseGalleryItem->image = 'img/uploads/' . $courseGalleryItemImageFileName;
             }
             $courseGalleryItem->course_id = $course->id;
             $courseGalleryItem->image_alt = $request->input('course-gallery-item-image-alt')[$key];
             $courseGalleryItem->save();
             if ($courseGalleryItemId != "") {
                 array_push($courseGalleryItemIds, $courseGalleryItemId);
             } else {
                 array_push($courseGalleryItemIds, $courseGalleryItem->id);
             }
         }
     }
     foreach ($course->courseGalleryItems as $courseGalleryItem) {
         if (!in_array($courseGalleryItem->id, $courseGalleryItemIds)) {
             $courseGalleryItem->delete();
         }
     }
     $course->courseProgramItems()->delete();
     if ($request->input('course-program-item-text') != null) {
         foreach ($request->input('course-program-item-text') as $courseProgramItemText) {
             $courseProgramItem = new CourseProgramItem(['text' => $courseProgramItemText]);
             $course->courseProgramItems()->save($courseProgramItem);
         }
     }
 }