Search
 
SCRIPT & CODE EXAMPLE
 

PHP

custom rule laravel validation

public function store()
{
    $this->validate(request(), [
        'song' => [function ($attribute, $value, $fail) {
            if ($value <= 10) {
                $fail(':attribute needs more cowbell!');
            }
        }]
    ]);
}
Comment

laravel custom validation rules

php artisan make:rule Uppercase
Comment

laravel custom validation

php artisan make:rule RuleName
Comment

validate rule on laravel

$request->validate([
    'title' => 'required|unique:posts|max:255',
    'body' => 'required',
    'publish_at' => 'nullable|date',
]);
Comment

laravel custom validation

namespace AppRules;

use IlluminateContractsValidationRule;

class GreaterThanTen implements Rule
{
    // Should return true or false depending on whether the attribute value is valid or not.
    public function passes($attribute, $value)
    {
        return $value > 10;
    }

    // This method should return the validation error message that should be used when validation fails
    public function message()
    {
        return 'The :attribute must be greater than 10.';
    }
}
Comment

Laravel validation rule

Accepted
Accepted If
Active URL
After (Date)
After Or Equal (Date)
Alpha
Alpha Dash
Alpha Numeric
Array
Bail
Before (Date)
Before Or Equal (Date)
Between
Boolean
Confirmed
Current Password
Date
Date Equals
Date Format
Declined
Declined If
Different
Digits
Digits Between
Dimensions (Image Files)
Distinct
Email
Ends With
Enum
Exclude
Exclude If
Exclude Unless
Exclude With
Exclude Without
Exists (Database)
File
Filled
Greater Than
Greater Than Or Equal
Image (File)
In
In Array
Integer
IP Address
JSON
Less Than
Less Than Or Equal
MAC Address
Max
MIME Types
MIME Type By File Extension
Min
Multiple Of
Not In
Not Regex
Nullable
Numeric
Password
Present
Prohibited
Prohibited If
Prohibited Unless
Prohibits
Regular Expression
Required
Required If
Required Unless
Required With
Required With All
Required Without
Required Without All
Required Array Keys
Same
Size
Sometimes
Starts With
String
Timezone
Unique (Database)
URL
UUID
Comment

create custom rule in laravel

<?php

namespace AppRules;

use IlluminateContractsValidationRule;

class Uppercase implements Rule
{
    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        return strtoupper($value) === $value;
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The :attribute must be uppercase.';
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: laravel response header 
Php :: how to show image from php 
Php :: get post by meta value 
Php :: not get child all data in relationship with parent laravel eloquent 
Php :: php http authentication 
Php :: carbon get day name 
Php :: unset php 
Php :: in_array associative array php 
Php :: filter collection (laravel) 
Php :: Syntax error or access violation: 1071 La clé est trop longue. Longueur maximale: 1000" 
Php :: adminlte 3 laravel 
Php :: laravel where 
Php :: get data of url php 
Php :: check request header laravel 
Php :: laravel model fillable vs guarded 
Php :: How to order by using id with firstWhere in laravel 
Php :: php array_intersect 
Php :: php ?? 
Php :: eloquent get record older than 2 days 
Php :: model find by certain column laravel 
Php :: check website ssl certificate using php 
Php :: sub menu for post type in wordpress 
Php :: php excel to array 
Php :: date hour php 
Php :: update image in database using php 
Php :: location php ini mac os 
Php :: showing from to in larvel pagination 
Php :: laravel hash password check 
Php :: laravel elequent query 
Php :: gettype() function in PHP 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =