Support the ongoing development of Laravel.io →
posted 9 years ago
Validation
Last updated 1 year ago.
0

Hello did you resolve this?

Last updated 1 year ago.
0

I have same issue likes @ChrisBinge's issue..

I have been registered my validation class that extends laravel validation class.


<?php namespace Muratsplat\Multilang;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;

use Muratsplat\Multilang\Picker;
use Muratsplat\Multilang\Validator;
use Muratsplat\Multilang\NewRules;
use Muratsplat\Multilang\Wrapper;

/* MultiLang Service Provider
 * 
 * @author Murat Ödünç <[email protected]>
 * @copyright (c) 2015, Murat Ödünç
 * @link https://github.com/muratsplat/multilang Project Page
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPLv3 
 */
class MultilangServiceProvider extends ServiceProvider {

	/**
	 * Indicates if loading of the provider is deferred.
	 *
	 * @var bool
	 */
	protected $defer = true;

	/**
	 * Bootstrap the application events.
	 *
	 * @return void
	 */
	public function boot()
	{
		$this->package('muratsplat/multilang');
	}

	/**
	 * Register the service provider.
	 *
	 * @return void
	 */
	public function register()
	{
            // adding new rules for our extention
            $this->addNewRules();

            $this->app->singleton('multilang', function($app) {               
            
                return new MultiLang(
                        
                        new Picker(new Collection(), new Element(),$app['config']),
                        $app['config'],
                        new MessageBag(),
                        new Validator($app['validator'], $app['config']),
                        new Wrapper($app['config'])
                        );
            });
                
	}
        
        /**
         * to add new rules to Laravel Validator object
         */
        private function addNewRules() {
  
            $this->app['validator']->resolver(function($translator, $data, $rules, $messages) {
                
                return new NewRules($translator, $data, $rules, $messages);
            });
        }

	/**
	 * Get the services provided by the provider.
	 *
	 * @return array
	 */
	public function provides()
	{
		return array('multilang');
	}

}

When the app is runtime, it need to accass to my valdiation rules and return this error: "BadMethodCallException: Method [validateRequiredForDefaultLang] does not exist."

It looks the resolver never call the callback function ..

How should I add my validation object to laravel via IoC ?

0

I have solved that issue..

Validator resolver must be run inside of boot method on service provider...

Last updated 9 years ago.
0

Hi

There's a package for phone validation.

https://github.com/Propaganistas/Laravel-Phone

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.