我正在使用laravel 5.8,我想在Request验证类中使用access global config(),但它不起作用
namespace App\Http\Requests;
use App\AppConstant;
use Illuminate\Foundation\Http\FormRequest;
class Something extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'url' => 'required',
'category' => 'in:'.implode(",", config('app.categories').''
];
}
}
这是我的config / app.php
的一部分return [
'name' => env('APP_NAME', 'Laravel'),
'categories' => [
'games',
'entertainment'
],
但输出是
Class App\\Http\\Requests\\Something does not exist
when i remove config() from request file it works very well
答案 0 :(得分:1)
您的代码在类别之后缺少右括号)。应该是
'category' => 'in:'.implode(",", config('app.categories')).''