Search
 
SCRIPT & CODE EXAMPLE
 

PHP

validation in laravel

use IlluminateSupportFacadesValidator;
 
class PostController extends Controller
{
    /**
     * Store a new blog post.
     *
     * @param  Request  $request
     * @return Response
     */
    public function store(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'title' => 'required|unique:posts|max:255',
            'body' => 'required',
        ]);
 
        if ($validator->fails()) {
            return redirect('post/create')
                        ->withErrors($validator)
                        ->withInput();
        }
 
        // Retrieve the validated input...
        $validated = $validator->validated();
 
        // Retrieve a portion of the validated input...
        $validated = $validator->safe()->only(['name', 'email']);
        $validated = $validator->safe()->except(['name', 'email']);
 
        // Store the blog post...
    }
}
Comment

validation laravel

/**
 * Store a new blog post.
 *
 * @param  IlluminateHttpRequest  $request
 * @return IlluminateHttpResponse
 */
public function store(Request $request)
{
    $validated = $request->validate([
        'title' => 'required|unique:posts|max:255',
        'body' => 'required',
    ]);
 
    // The blog post is valid...
}
Comment

sometimes validation in laravel

Docs don't make it clear, But removing required makes it work.

$this->validate($request, [
    'password' => 'sometimes|min:8',
]);
Comment

PREVIOUS NEXT
Code Example
Php :: php dar echo em um stdClass 
Php :: php update sql database from form 
Php :: hasmany relation in laravel 
Php :: php session destroy not working 
Php :: php preg match 
Php :: use htaccess to redirect in cpanel laravel 
Php :: Laravel unique with Validation rule 
Php :: hot to use functions in heredoc 
Php :: php using composer autoload 
Php :: How to get a list of registered route paths in Laravel? 
Php :: drupal 8 $_GET 
Php :: check count in laravel 
Php :: get object value by key php 
Php :: php keep input value after submit 
Php :: wp_mail multiple recipients 
Php :: withcookie function in php 
Php :: php dump to page 
Php :: This domain is not registered with Tiny Cloud. Please see the quickstart guide or create an account. 
Php :: laravel test filter 
Php :: Laravel unique cheque using multiple column 
Php :: laravel get route action 
Php :: pessimistic locking laravel 
Php :: 0 
Php :: laravel all 
Php :: php triple quotes 
Php :: laravel kill current session 
Php :: get city name from latitude and longitude in php using geocode api 
Php :: Warning: password_verify() expects parameter 2 to be string, array given in 
Php :: php match expression 
Php :: php strings 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =