public function getBySlug($slug)
{
$book = $this->bookQuery()->where('slug', '=', $slug)->first();
- if ($book === null) throw new NotFoundException('Book not found');
+ if ($book === null) throw new NotFoundException(trans('errors.book_not_found'));
return $book;
}
*/
public function updateFromInput(Book $book, $input)
{
+ if ($book->name !== $input['name']) {
+ $book->slug = $this->findSuitableSlug($input['name'], $book->id);
+ }
$book->fill($input);
- $book->slug = $this->findSuitableSlug($book->name, $book->id);
$book->updated_by = user()->id;
$book->save();
$this->permissionService->buildJointPermissionsForEntity($book);
*/
public function findSuitableSlug($name, $currentId = false)
{
- $slug = Str::slug($name);
- if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5);
+ $slug = $this->nameToSlug($name);
while ($this->doesSlugExist($slug, $currentId)) {
$slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
}