Ejemplo n.º 1
0
 /**
  * Register the listeners for the subscriber.
  *
  * @param \Illuminate\Events\Dispatcher $events
  * @return void
  */
 public function subscribe($events)
 {
     Recipe::observe('App\\Observers\\RecipeModelObserver');
     $events->listen('App\\Events\\Recipe\\RecipeCreated', 'App\\Listeners\\RecipeEventListener@onRecipeCreated');
     $events->listen('App\\Events\\Recipe\\RecipeUpdated', 'App\\Listeners\\RecipeEventListener@onRecipeUpdated');
     $events->listen('App\\Events\\Recipe\\RecipeDeleted', 'App\\Listeners\\RecipeEventListener@onRecipeDeleted');
 }
Ejemplo n.º 2
0
 /**
  * Sync a recipe's categories.
  *
  * @param Recipe $recipe
  * @param int|array $categories
  * @return Recipe
  */
 public function syncCategories(Recipe $recipe, $categories)
 {
     $categories = is_array($categories) ? $categories : [$categories];
     $recipe->categories()->sync($categories);
     return $recipe;
 }