app/Http/Controllers/BookController.php
/**
     * Resolves a category ID, even if a given category name is a string
     * (user input could be anything)
     *
     * @param string|int $category
     * @return int
     */
Resolves a category ID, even if a given category name is a string
(user input could be anything)

@param string|int $category
@return int
Resolves a category ID even if a given category name is a string ( user input could be anything ) @param string|int $category @return int
protected function resolveCategoryId($category)
    {
        if (!is_numeric($category)) {
            $categoryTrim = trim($category);
            $categoryId = Category::query()->where('name', 'like', "%$categoryTrim%")->get(['id'])->toArray()[0]['id'];
        } else {
            $categoryId = $category;
        }
        return $categoryId;
    }
protected function resolveCategoryId ( $ category ) { if ( ! is_numeric ( $ category ) ) { $ categoryTrim = trim ( $ category ) ; $ categoryId = Category :: query ( ) -> where ( 'name' , 'like' , " % $ categoryTrim % " ) -> get ( [ 'id' ] ) -> toArray ( ) [ 0 ] [ 'id' ] ; } else { $ categoryId = $ category ; } return $ categoryId ; }
Resolves a category ID, even if a given category name is a string
 (user input could be anything)
Resolves a category ID even if a given category name is a string ( user input could be anything )