Skip to content
Snippets Groups Projects
isNameForCategoryAvaiable.php 516 B
Newer Older
Shizuco's avatar
Shizuco committed
declare (strict_types = 1);

namespace App\Rules;

use App\Models\Category;
Shizuco's avatar
Shizuco committed
use Illuminate\Contracts\Validation\Rule;

class isNameForCategoryAvaiable implements Rule
{
Shizuco's avatar
Shizuco committed

    public function __construct()
    {
        //
    }

    public function passes($attribute, $value)
    {
        $category = Category::where('name', $value)->get();
        return (count($category) === 0) ? true : false;
    }

    public function message()
    {
        return 'Category with this name ia already exists.';
    }
}