App\Repositories\PostRepository::parseCategory PHP Method

parseCategory() public method

Get or create new category and return category id.
public parseCategory ( $name ) : mixed
$name category name
return mixed category id
    public function parseCategory($name)
    {
        $category = $this->category->whereName($name)->first();
        if (is_null($category)) {
            $category = new $this->category();
            $category->name = $name;
            $category->save();
        }
        return $category->id;
    }