Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mailnike's avatar

Using Laravel Spark without Vue.Js

Hi,

I've created a API that my HTML/AJAX frontend consumes. However - it seems SPARK requires VUE.JS otherwise TOKEN (or credentials) will not be passed automatically. Is there any workaround for this? I tried to pass CSRF token in my AJAX request but no luck.

Also, statement "$company_id = Auth::user()->currentTeam->id;" generates an error if Vue.JS is not used on the frontend. Do I need to maintain something in order to avoid this? Sorry to ask rookie questions but many resources available on this - specially when I am not using VUE.JS.

0 likes
5 replies
ejdelmonico's avatar

Well, I am not sure what you are after exactly but Spark requires Vue 2 and Bootstrap to function. Both are heavily integrated with the framework. In short, you must use them for Spark but you can use whatever you want for the rest of your app. In your post, the Auth::user() comes from Laravel framework auth but the currentTeam->id comes from the Vue object. Maybe that will help you. Also, Spark provides a bunch of events you can hook into so maybe you could do a listener that produces what you require for your app.

1 like
mailnike's avatar
mailnike
OP
Best Answer
Level 5

Hi @ejdelmonico thanks for your reply. If I am using JQuery or other JS with Spark, then it seems I need to encrypt the CSRF token, pass it to the frontend and then pass it back in the AJAX request header.

1)) from backend to the view = withEncryptedCsrfToken(Crypt::encrypt(csrf_token()))

2)) from view to the backend (ajax) =

$.ajaxPrefilter(function(options, originalOptions, xhr) { var token = '{{ $encrypted_csrf_token }}'; if (token) { return xhr.setRequestHeader('X-XSRF-TOKEN', token); } });

However, I am not sure how secure it is or whether it is a best practice or not.

Now, currentTeam->id comes from the Vue Object thats a big turn off :( ... I will check Spark events. Thanks for your help.

ejdelmonico's avatar

There is plenty of examples and docs for passing the CSRF token when using ajax on this forum. Also, it would seem like you need to construct maybe an interface that makes the Spark info passable to your frontend.

1 like
mailnike's avatar

@ejdelmonico true. Here, you can't just pass CSRF token but you need to encrypt it. Just passing CSRF doesn't work.

Yes, good idea about interface will check that too.

ejdelmonico's avatar

I can't recall but I thought I can recall something about a config option for encrypting...you might want to search around for that.

Please or to participate in this conversation.