public function beforeCreate() { $newsLink = '/news/' . $this->category . '/item/' . $this->slug; if ($this->needKnow) { $link = Link::create(['title' => $this->title, 'description' => $this->short_description, 'link' => $newsLink, 'category' => 'needKnow', 'active' => true]); $link->photo = isset($this->photos[0]) ? $this->photos[0] : null; $link->save(); } else { $links = Link::where('link', $newsLink)->get(); foreach ($links as $item) { $item->delete(); } } if ($this->news) { $link = Link::create(['title' => $this->title, 'description' => $this->short_description, 'link' => $newsLink, 'category' => 'news', 'active' => true]); $link->photo = isset($this->photos[0]) ? $this->photos[0] : null; $link->save(); } else { $links = Link::where('link', $newsLink)->get(); foreach ($links as $item) { $item->delete(); } } }
public function beforeCreate() { $articleLink = '/articles/' . $this->slug; if ($this->needKnow) { $link = Link::create(['title' => $this->title, 'description' => $this->short_description, 'link' => $articleLink, 'category' => 'needKnow', 'active' => true]); $link->photo = $this->photo; $link->save(); } else { $links = Link::where('link', $articleLink)->get(); foreach ($links as $item) { $item->delete(); } } if ($this->news) { $link = Link::create(['title' => $this->title, 'description' => $this->short_description, 'link' => $articleLink, 'category' => 'news', 'active' => true]); $link->photo = $this->photo; $link->save(); } else { $links = Link::where('link', $articleLink)->get(); foreach ($links as $item) { $item->delete(); } } }