jeudi 30 mai 2019

Laravel Using config() in request validation

I'm using laravel 5.8 and I want to use access global config() in Request validation class but it does not work

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').''
        ];
    }
}

and here is part of my config/app.php

return [

    'name' => env('APP_NAME', 'Laravel'),
    'categories' => [
        'games',
        'entertainment'
    ],


but the output is


Class App\Http\Requests\Something does not exist

when i remove config() from request file it works very well



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire