laravel 5.1中的验证错误(数组到字符串的转换) [英] Validation Error (Array to string conversion) in laravel 5.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)
代码:
<?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
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',
);
推荐答案
似乎config/app.php中的locale值是一个数组,而vendor/laravel/framework/src/Illuminate/中的loadPath函数Translation/FileLoader.php希望它是一个字符串. 因此,我建议您在配置文件中将其值设置为"en"或"sv",然后根据需要在代码中以编程方式对其进行更改.
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.
这篇关于laravel 5.1中的验证错误(数组到字符串的转换)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!