[Vuejs]-Passing array containing accents from Laravel to vue.js

0πŸ‘

βœ…

The problem was from the function strftime which have some bugs according to this post. So I changed the controller like that :

public function dashboard($userToken)
{
    $data = [];
    $data['projects'] = $this->user->listprojects($userToken);

    if (App::isLocale('fr')) {
        setlocale(LC_TIME, "fr_FR");
    } else {
        setlocale(LC_TIME, "en_US");
    }

    foreach ($data['projects'] as $project) {
        $project->date = utf8_encode(strftime('%d %B %Y - %H:%M',$project->date) );
    }
    return view('dashboard',compact("data"));
}

And the view like @Babak suggested :

<script>
    var app = new Vue({
        el: '#app',
        data: {
            presentations: <?php echo(json_encode($data['projects'])) ?>
        }
    });
</script>
πŸ‘€Core972

2πŸ‘

convert your array to json like this

return view('dashboard',compact("data"));

and then in Vue.js convert it back.

Leave a comment