1

I am wanting to pass the data from my app controller to my vue:

class AppController extends Controller
{
    /**
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        return response()
            ->view('pages.app', ['highScore' => HighScore::getHighScore()], 200);
    }
}

Here is my routes managed in vue:

const routes = [
    {
        path: '/',
        name: 'home',
        component: Home,
        meta: { bodyClass: 'page' },
        props: true
    },
]

Now within my home view I am populating the following within props:

props: ['highScore']

But it is undefined, any help would be appreciated

2
  • You can axios to make laravel api calls. Commented Jun 25, 2021 at 5:48
  • @dev, thanks, I am wanting to reduce the amount of calls Commented Jun 25, 2021 at 6:23

2 Answers 2

2

In the controller you pass the data as usual from controller to a blade view. I use this syntax:

enter image description here

Then, on the Blade View you have to add the VueJs component and pass the same data like this:

enter image description here

Now you can access all those variables on the Vue component.

Sign up to request clarification or add additional context in comments.

1 Comment

The correct way to pass those data should be:allbrands="{{$brands}}". Otherwise there will be error, the string rendered from {{$brands}} will reported as undefined by Vue
0

In the jetsteam/inertia setup it's done like this:

Route::get('/page4', function () {
    $allusers = ['aa','bb','cc'];
    return Inertia::render('Page4',
        ['users' => $allusers]);
})

If it's a new projet? i recomment this, cause it makes it easier. https://jetstream.laravel.com/2.x/stacks/inertia.html

2 Comments

I am aware of that solution but I am extending a current project that does not use Jetstream
Check if passing to an normal blade works and check what values for your variables the vue extension for chrome shows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.