Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Laravel 4 Basics Validation & Flash Messages Basic Validation

bruce zhang
bruce zhang
1,317 Points

Validator Error

Hi, I keep getting this error when I use laravel validator

ErrorException (E_UNKNOWN)

preg_replace(): Parameter mismatch, pattern is a string while replacement is an array Open: /home/vagrant/sites/zihai/vendor/laravel/framework/src/Illuminate/Support/helpers.php

<?php
   /**
    * @param string $subject
    * @return string
    */
    function str_replace_array($search, array $replace, $subject)
    {
    foreach ($replace as $value)
    {
    $subject = preg_replace('/'.$search.'/', $value, $subject, 1);
    }

my code simply like that

<?php
$rules = array(
            'title' => array('required')
        );
        $name = Input::all();   

        $validate = Validator::make($name,$rules);

1 Answer

Petros Sordinas
Petros Sordinas
16,181 Points

Bruce,

Something is passed incorrectly to the Validator::make method. Can you show us your form code?

bruce zhang
bruce zhang
1,317 Points

Hi Petros,

Thanks for your reply, I finally found the issue. validator are perfect, the issue was happen when passing data to ORM.

sorted

Regards Bruce