Laravel Spark

0 views
Skip to first unread message

Shawana Messerli

unread,
Aug 3, 2024, 5:22:57 PM8/3/24
to provnaunaro

I have a very simple problem. I just want to direct the user to somewhere other than '/home' after they login. This is not difficult if you can alter the spark software and retain those changes in every deployment. However, composer reinstalls everything when things are deployed and it is generally bad practice to make changes to core vendor software.

I got a new github token and placed it into the auth.json file as was done with the previous bitbucket repo (it's a private repo). However, when I push to heroku to build the code with composer there, I cannot connect with the laravel spark repo.

I am connected to the Laravel Spark repo on github and when I run composer on my local machine I am not prompted for a spark token. Every other dependency that I have runs fine - I can change the auth.json and that is not the case, so I don't think this is a problem with lack of access to my github.

The response from the software providers is to use an alternative method and place the code under my source control so that composer is not trying to load it. I do not wish to do this for a number of reasons. Again, I need a way to clone the satis repo in composer.

Edit 4: It occurred to me that my problems started after upgrading to V6 and I am getting denied access to the spark repo containing versions 1-5 and version 6 is separate. I upgraded my spark version to 6 and had access to that repo. I then tried uploaded the code base to heroku that had version 6 but was denied access to the repo there.

So, it turns out there were several issues. The final big one was that for some reason, I had to delete my api personal token used for github access and create a new one with full privileges for everything. Once that was set up, I had access and was able to reduce the privileges to repo only.

Taylor Otwell shared a demo of the next major version of Laravel Spark, showing the power of the next generation of Spark by going from "laravel new" to a subscription-based SaaS application in ten minutes:

As you'll see in the demo, Spark allows you to quickly set up subscription plans for your application and provides your customers with a billing portal. The billing portal lets users select from available plans, upgrade, pause subscriptions, and view billing history, including invoices.

Laravel Spark is a paid major version and successor of Laravel Spark Classic. The next version is designed to be an isolated billing portal that's separate from your application. Since it's self-contained, it doesn't affect any technology choices you want to build your application.

Spark will be available for purchase starting on Tuesday, February 16th. Make sure you get on the waiting list for earliest access and launch specials! Sign up today on spark.laravel.com!

Background: I set up a Laravel / Spark project. Out of the box it gives me the normal user authentication method of username and password, AND I can use the REST API with tokens! Tokens are awesome, it basically replaces the username / password, so I can make authenticated requests to the API and know who the user is!

Modifying the api_tokens table was straightforward. Just open up the migration file for the tokens in database/migrations/, add the two new column types, slightly modify the index, and refresh the migration. DONE.

CMD+T searching for TokenRepository again brings up two files. We need the one that does not have Contract in its path as one of them (the non-contract one) implements the other one (the contract one).

I changed the static Route::get methods to $route->get, and used the dynamic versions going forward. Reason I can do that is because $router is defined / passed on to the router file in app/Providers/RouteServiceProvider.php.

I assume that $user in this case is the User model, of which I have one in the app directory. That one extends SparkUser which is just Laravel\Spark\User found in the file spark/src/User.php. That one has a trait on it: HasApiTokens.

Traits are an easy way to sideload additional methods onto classes. They are kind of weird to redeclare, but I digress. The HasApiTokens trait is in the file spark/src/HasApiTokens.php. That one declares a tokens method. Which means that when TokenSecretRepository calls $user->tokens()->, the method on the trait gets executed. Phew.

That one returns an Eloquent model relationship of the class Token. The trait is in the namespace Laravel\Spark, so the Token will also be there. The file, after some rummaging, is spark/src/Token.php.

So I thought I would just write a custom trait HasApiTokenSecrets, only declare the methods that have the Token class in it, change it to my TokenSecret class which extends the Token class and redeclares the $hidden property to be empty, and we should be set.

I stuck a console.log(response); into the create method of create-token.js (ours) just to see what the data. Turns out only the token is being sent across. The source of that is probably TokenSecretController@store:

So you want to setup your own SaaS? Laravel Spark is a fantasic boilerplate to help get you started, but getting started is the hard part. I've personally found that getting it to install correctly first time is somewhat of an art. I've always ran into errors such as: Class 'App\Providers\SparkServiceProvider' not found. Or composer complaining that i don't have the right dependencies and i need to downgrade my version of Cashier etc.

Having tried to fire up a new Spark install with some new updates, i was STILL running into the SparkServiceProvider not found! It turns out that having everything up-to-date is the problem here. This time around it was my version of Composer. I was running 1.6.3 and the latest at the time of writing is 1.9.2

I'm going to reference the Spark Docs a lot here as it does offer great advice, you just need to understand where things go in order to make it all work! So fire the docs up in another tab and let's get started.

At this point you can just follow the Spark docs. It's also the first time you'll be using the spark command in your terminal. If you can register your API token with no problems, it means you've sucessfully added the spark installer to your systems $PATH. If not, go back into your zshrc or bash_profile and double check the paths to the spark installer. You may also have to close down your terminal and open it back up again for it to pick up the changes.

The problems i faced were that my laravel installer was out of date and the path to the Spark installer was pointing to an old version as well as the wrong folder. Its easy to overlook these things, but also easy to fix!

You could make an api, which would check if the user exists and returns the login credentials. I don't really understand the question, as Spark is a billing platform, and not an Auth infrastructure. Do you mean login a spark user? The documentation states that you should make a composer auth.json and then use an api token to login your user

Sorry, I'm very new to Spark and Laravel in general. I don't mean to login a Spark user (admin). When the end user visits the site he has to register for an account and subscribe so I figured it should have some auth built-in?Or do I have to use Jetstream separately? Spark Classic had user accounts so I'm not sure what is the way to go with Spark next.

We all start somewhere, so digging deeper into the documentation, we see that it says you should read up the spark middleware documentation -paddle/middleware.html and that you can use laravel cashier methods -paddle#checking-subscription-statusMight I suggest you take a look at =czh8oO7lVx0 this tutorial by Povilas Korop, his channel provides quality free tutorials in regards to Laravel

You should clone this repository to any location on your system, then run the composer install command within the cloned directory so the installer's dependencies will be installed. Finally add that location to your system's PATH so that the spark executable can be run from anywhere on your system.

Oh Dear is the all-in-one monitoring tool for your entire website. We monitor uptime, SSL certificates, broken links, scheduled tasks and more. You'll get a notifications for us when something's wrong. All that paired with a developer friendly API and kick-ass documentation. O, and you'll also be able to create a public status page under a minute. Start monitoring using our free trial now.

Oh Dear is a Laravel application. When we launched, we used what is now called the classic version Laravel Spark to take care of team management and billing. A few weeks ago, the Laravel team launched a modern version of Spark with a lighter footprint.

Classic Spark was, at the time when it was launched, a very convenient way of bootstrapping a SaaS. It provided billing, subscription and team management, and a few extras such as notifications and the ability to impersonate users.

It's likely that if Horizon or classic Spark didn't exist, Oh Dear probably wouldn't have happened. The existence of both these packages gave Mattias and me room to work on the core features of our app. It prevented us from losing ourselves in the intricacies of queuing, billing and subscription handling.

Besides backend functionality, classic Spark also included a UI to handle team, billing and subscription management. The UI was built entirely using Vue components. For people that at the time were already familiar with Vue, this was great! But a part of the community, Vue hadn't "clicked" yet, and Blade was the preferred way to build screens.

Even though at the time, both Mattias and I didn't have too much experience with Vue, we went ahead with using Spark because it could save us so much time. For us, the downside was that customizing the UI and certain parts of the default Spark behaviour was hard to do. Sure, you could skip using the provided Vue components and only use the backend of Spark (that what we did when building Flare), but it's time-consuming to do so.

c80f0f1006
Reply all
Reply to author
Forward
0 new messages