Posted inTechnology / Ajax / Laravel / Programming / VueJs

Laravel Vuejs Ajax Validation Tutorial With Example

Today, We want to share with you Laravel Vuejs Ajax Validation Tutorial.In this post we will show you Simple Laravel Vuejs Form Validation Example, hear for file upload size limit validation in vuejs we will give you demo and example for implement.In this post, we will learn about Image upload and validation using Laravel and VueJs with an example.

Laravel Vuejs Ajax Validation Tutorial

There are the Following The simple About Laravel Vuejs Ajax Validation Tutorial Full Information With Example and source code.

As I will cover this Post with live Working example to develop Vuejs Form Validation Tutorial With Example From Scratch , so the someSimple Laravel Vuejs Form Validation for this example is following below.

Step 1 : Create Vuejs components

resources/assets/js/components/FileUpload.vue

Image upload and validation using Laravel and VueJs

Step 2: register vuejs

FileUpload component Simple register it in app.js

Vue.component('file-upload',require('./components/FileUpload.vue'));

vuejs registered our component


Step 3: Laravel View Files

welcome.blade.php

@extends('layouts.app')

@section('content')

Image upload and validation using Laravel and VueJs

Upload your Members Profile image!
@endsection

Setp 4 : Define a Laravel Routes

Laravel Route(axios post method)

Route::post('/upload', function (Request $datarequest) {
    $validator = Validator::make($datarequest->all(), [
        'image' => 'required|image64:jpeg,jpg,png'
    ]);
    if ($validator->fails()) {
        return response()->json(['errors'=>$validator->errors()]);
    } else {
        $allImgData = $datarequest->get('image');
        $myfileName = Carbon::now()->timestamp . '_' . uniqid() . '.' . explode('/', explode(':', substr($allImgData, 0, strpos($allImgData, ';')))[1])[1];
        Image::make($datarequest->get('image'))->save(public_path('uploads/').$myfileName);
        return response()->json(['error'=>false]);
    }
});

AppServiceProvider

public function boot()
{
    Validator::extend('image64', function ($attribute, $value, $allparamval, $validator) {
        $type = explode('/', explode(':', substr($value, 0, strpos($value, ';')))[1])[1];
        if (in_array($type, $allparamval)) {
            return true;
        }
        return false;
    });

    Validator::replacer('image64', function($message, $attribute, $rule, $allparamval) {
        return str_replace(':values',join(",",$allparamval),$message);
    });
}

validation.php

'image64' => 'The :attribute must be a Live file of type: :values.',

'custom' => [
        'attribute-name' => [
            'rule-name' => 'custom-message',
        ],
    ],
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel Vuejs Ajax Validation Tutorial.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype