How to get values in multilingual websites



  • What is the proper way to get request values in a multilingual website?

    I can't use $request->all() because I have a "published or not" field (checkbox)

    $published = $request->has('published') ? true : false;

    $this->article->create([
    'title' => $request->input("en.title"),
    'slug' => $request->input("en.slug"),
    'body' => $request->input("en.body"),
    'published' => $published,
    ]);
    

    How to save other locales?


  • Global Moderator

    @Photoshopper

    You already getting them properly (just not saving properly).

    If you want to supply $request->all() to create method you have to trick the system so to say.

    For example you could do something like this in your create form:

    {{ Form::hidden('published', false) }}
    {{ Form::checkbox('published', true) }}
    

    This way published will always be present and will contain value of true or false.

    Something like this will probably work also if you want non-html way(personaly i would keep this in view).

    $article_data = $request->all();
    $article_data['published'] = $request->has('published') ? true : false;
    
    $this->article->create($article_data);
    


  • Thank you. Both ways work fine. I chose the first one


Log in to reply