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

laravel validation on update

public function controllerName(Request $request, $id)
{
    $this->validate($request, [
        "form_field_name" => 'required|unique:db_table_name,db_table_column_name,'.$id
    ]);
    // the rest code
}
Comment

laravel validation on update

public function controllerName(Request $request, $id)
{
    $this->validate($request, [
        "form_field_name" => 'required|unique:db_table_name,db_table_column_name,'.$id
    ]);
    // the rest code
}
Comment

PREVIOUS NEXT
Code Example
Php :: drupal show php errors 
Php :: php const in class 
Php :: decrypt md5 php 
Php :: pagination always show 5 pages 
Php :: no sass folder in laravel 
Php :: mysqli connect error 
Php :: octobercms mail 
Php :: isset in php 
Php :: livewire check no errors 
Php :: run phpstan terminal 
Php :: Bootstrap paginator css not appearing 
Php :: Web servers supported by php 
Php :: php post not working 
Php :: Cannot modify header information - headers already sent by 
Php :: Fetch pivot data laravel 
Php :: foreach loop in php stack overflow 
Php :: query log laravel 
Php :: how to add image in wordpress theme 
Php :: cakephp sql query 
Php :: cakephp find_in_set 
Php :: hint extension in visual studio code for laravel 
Php :: what are the different types of PHP variables? 
Php :: php class 
Php :: if user not signed in redirected to login laravel from route 
Php :: PHPDoc @method 
Php :: send email verification nootification laravel 
Php :: API call in PHP using cURL 
Php :: laraodck imagick 
Php :: get data in php 
Php :: define multiple variables in one line php 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =