[Vuejs]-How to pass an array of routes from blade.php to a Vue component in Laravel

0๐Ÿ‘

Iโ€™m pretty useless when it comes to Laravel but it sounds like you want to map the $exam array to an array of routes (returned by that route function).

Try this

<user-exam
  :routes="{{ json_encode( array_map(function($ex) {
    return route('user.exam-start', ['exam' => $ex]);
  }, $exam) ) }}"
></user-exam>

0๐Ÿ‘

I found a solution to my issue, I ended up looping in the blade file like this

@foreach($exam as $ex)
<user-exam
        :routes="{{ json_encode( route('user.exam-start', ['exam' => $ex]))}}"
  ></user-exam>
@endforeach

THis ends up creating multiple instances of the vue component but it is working as I wanted it to.

Sin the vue dev tools you have something like:

<Root>
    <userExam>
    <userExam>
</Root>

Leave a comment