我正在使用 laravel 5.8 并且我想在请求验证类中使用访问全局 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
您的代码在类别后缺少右括号 )。它应该是
'category' => 'in:'.implode(",", config('app.categories')).''
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句