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.
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.
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.
Please or to participate in this conversation.