jeudi 25 juin 2020

Creating a package for validation. I want that my package can use be useable like-use Validation; Excel::alphanumeric()

Please help anyone if could get my vallidation in controller as use Excel; //this is our package Excel::load() // this is a function for load the excel

This is my Custom Rule

    namespace pebibits\validation\Rules;

use Illuminate\Contracts\Validation\Rule;

class Alphanumeric implements Rule
{
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        // dd("ok");
        
        return preg_match('/(^[\w-]*$)/',$value);
        
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'You can only have aplhabates.';
    }
}

This is my controller

    <?php

namespace pebibits\validation\Http\Controllers;
use pebibits\validation\Rules\Alphanumeric;
use pebibits\validation\Requests\Formvalidate;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class FormController extends Controller
{
    public function index()
    {
        return view('validation::form');
    }

    public function store(Formvalidate $request)
    {

       return $request->all();
    }
}

Please help anyone if could get my vallidation in controller as use Excel; //this is our package Excel::load() // this is a function for load the excel



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/31ejBUo
via IFTTT

Aucun commentaire:

Enregistrer un commentaire