1

I'm struggling a couple of hours to fix this error but no luck please I need help about this error always says: (Array to string conversion)

Code:

<?php 
namespace App\Http\Controllers;
use Validator;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Hash, Auth, URL, Route, Cart, View, Paypal;
use App\Product, App\ProductBenefit, App\Country, App\Currency, App\User, App\City;

class HomeController extends BaseController {
public function postCheckoutStepPayment(Request $request){
        if(!is_null($request->input('ship_to_diff_address'))){
            $validate = Validator::make($request->all(), User::$rules);
            if($validate->fails()) { //<- problem this part
               return 'failed';
            }

        }
   }
}

User.php

public static $rules = array(
             'diff_firstname' => 'required',
             'diff_lastname'  => 'required',
             'diff_phone'     => 'required',
             'diff_countries' => 'required',
             'diff_city'      => 'required',
             'diff_state'     => 'required',
             'diff_address'   => 'required',
             );

enter image description here

12
  • What is the error you are getting? Commented Dec 16, 2015 at 12:36
  • @MinaAbadir Array to string conversion error Commented Dec 16, 2015 at 12:40
  • Possible duplicates: stackoverflow.com/questions/25691523/… Commented Dec 16, 2015 at 12:44
  • @MinaAbadir that answer is not clear to me Commented Dec 16, 2015 at 12:54
  • I am saying it's a possible duplicates. Are you using any classes that might change the default behavior of passing requests input? Commented Dec 16, 2015 at 12:55

3 Answers 3

1

It appears that the value for locale in your config/app.php is an array, whereas the function loadPath in vendor/laravel/framework/src/Illuminate/Translation/FileLoader.php expects it to be a string. So I suggest you to set it's value to either 'en' or 'sv' in the config file and then later change it programmatically in your code as required.

Sign up to request clarification or add additional context in comments.

1 Comment

Your the best @Vikas you save my day thank you very much :)
0

add use Redirect at the top, and

 public function postRegister(Request $request)
        {
            $v = Validator::make($request->all(), [
             'firstname' => 'required',
             'lastname'  => 'required',
             'phone'     => 'required',
             'countries' => 'required',
             'city'      => 'required',
             'state'     => 'required',
             'address'   => 'required',
            ]);

            if ($v->fails()) { 
                return redirect::to('register')
                            ->withErrors($v->messages())
                            ->withInput();
            }


        }

4 Comments

You don't need use Redirect when using redirect(), only when using Redirect::to(), and what did you change about postRegister(), the variable name?
instead of $validator, $validator->messages()
@Sid actually there's no problem with that part my problem is the if statement if ($v->fails()) this part something went wrong
@Sid take a quick look i am updating my post
0

Add this class in you controller

use App\Http\Requests;

And Try this code in blade file.

 @if(isset($errors))
     <ul style="list-style: none;" class="alert alert-warning">
     @foreach($errors->all() as $content)
         <li>{{$content}}</li>
     @endforeach
     </ul>
 @endif

3 Comments

My controller can't proceed to the view because of the error in validation part in my controller
check request have variable. first line befor $v .print_r($request->all());
take a quick look i am updating my post

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.