dimsav / laravel-translatable

[Deprecated] A Laravel package for multilingual models
MIT License
1.95k stars 320 forks source link

Validation messages #310

Closed elwafa closed 6 years ago

elwafa commented 7 years ago

Thanks for beautiful package I use this package , laravel-localization and Laravel-Translatable-Bootforms Here some of my code in controller `

     public function postAdd(Request $request)
{
    $rules = [
        'active' => 'boolean',
    ];

    foreach($request->get('title') as $key => $val)
    {
        $rules['title.'.$key] = 'required|max:10';
    }
    $validator = Validator::make($request->all(), $rules);
    if($validator->fails())
    {
        return dd($validator->errors());
    }

    if($validator)
    {
        $trip = New Trip();
        $request->has('active') ? $trip->active = 1 :  $trip->active = 0;
        $trip->save();
        foreach (LaravelLocalization::getSupportedLocales()  as $localeCode => $properties)
        {
            $trip->translateOrNew($localeCode)->title = $request->title[$localeCode];
        }
        $trip->save();
        return 'Done';
    }
    else
    {
        return 'Failed';
    }

}

and this is my blade

                       {!! BootForm::open()->action( route('trip.postForm')) !!}
                              {!! TranslatableBootForm::text(trans("trip.add.titleLabel"), 'title')->name('title[locale]')
                                                      ->attribute('some-attribute', 'Name: %name')
                                                      ->attribute('another-attribute', 'Locale: %locale')
                                                       ->class('form-control')
                                                       ->placeholder(trans('trip.add.title'))
                               !!}
                            {!! BootForm::checkbox(trans('trip.add.active'), 'active') !!}`
              {!! BootForm::submit(trans('trip.add.submit'))->class('btn btn-danger') !!}
                              {!! BootForm::close() !!}

`

Ok now when i post error validate input i want to display according to the language which user select i put in a validation lang in array attributes the name of my attribute in my case is title.en and title.whatever like this 'title.en' => 'title' 'title.whatever' => 'some language' and it worked but what If i put more language in the future i have to edit in lang validation file so what can i do to make the key of title.anything more dynamic

dimsav commented 7 years ago

Why not fetch the locales list from the config?

Gummibeer commented 6 years ago

closed due to inactivity