در حال بارگذاری ...

Introducing Laravel Spark0:00

Hi, this is Taylor Otwell, back with another Laravel screencast. And in this screencast, I'm proud to show you Laravel Spark. Spark is the latest addition to the Laravel family or ecosystem, so to speak. And it provides a starting point and scaffolding for your next big idea, your next business idea, your next side project idea, or maybe the next project at the company you're currently working for. And in this screencast, I just want to give you a quick overview of what Spark is and kind of what it looks like to install it and to poke around in Spark itself just a little bit. So Spark comes with an installer, just like Laravel, and we can actually just

Installing a Spark App0:30

itself just a little bit. So Spark comes with an installer, just like Laravel, and we can actually just run a spark-new and then the name of our project that we want to create. So in this example, I'm going to do spark-new-demo. And when I do that, that's going to create a new Laravel application and then install Spark and then ask us a few other questions about what we want to do, such as install our NPM dependencies and run gulp. Now, right now it's installing the Spark dependency, so we'll let that go through. And basically, this gives you a ready-made Spark project that you can start using and start building.

And this will just compile those dependencies and get them ready. All right, this should be about done, and then we're ready to take a look at our demo project. So let's change into that directory and open that up in Sublime Text. Now, if we hit this URL in our browser, you can see that we get a nice landing page here, Spark has been installed successfully, and we're ready to either log in or register with our application. Now, let's go back to Sublime Text. Now, when you create a new Spark application, it looks a lot like a default Laravel application.

Exploring Project Structure1:58

Now, when you create a new Spark application, it looks a lot like a default Laravel application. You can see I've got all the typical directories like app and bootstrap and config and so on, but I do have a new directory called Spark. And this is where all of the Spark source code lives, all of Spark's controllers, all of Spark's console commands all live within that directory. So how that's actually installed is it updates your composer.json file. Let me make this a little bigger for you. It updates your composer.json file to use the path type repository. Now, this is a composer option that lets you point to a specific directory that

Updating Spark via Artisan2:25

It updates your composer file to use the path type repository. Now, this is a composer option that lets you point to a specific directory that contains a Git repository or just any PHP project and lets you install that using its composer.json. So it will look at all of Spark's dependencies and install those and as well as its autoload paths. It's a really cool composer feature. All right. Now to update Spark, we wouldn't just do a plain composer update. We would actually come on the command line and type php artisan spark update.

Now to update Spark, we wouldn't just do a plain composer update. We would actually come on the command line and type php artisan spark:update. And that would update Spark. Now I just installed it. So I'm already on the latest release, but if there was a new version, it would download it and install it and then update any views that we have not yet modified, but you can check your Spark version with the spark:version command, which you can see I'm running 0.1.2, which is just a beta release of Spark. All right. And now let's take a look at Spark itself.

Configuring SparkServiceProvider3:20

All right. And now let's take a look at Spark itself. So if we close our terminal, let's take a look at the SparkServiceProvider. Now when Spark is first installed, it copies over a SparkServiceProvider into your app/Providers, SparkServiceProvider file, and this file contains a variety of options you can use to configure Spark, such as your company address and location, which would be placed on your invoices for your customers, an email address where your support email addresses can be sent, an array of all of your developers' email addresses, which grants them access to the developer kiosk section of Spark, which we'll talk

You can fill this out with, for example, if you allow unlimited whatever on your basic plan, you would put that in your feature list so that users can see that on the registration page. Now this providerId, I'm going to change to sparkTestOne, because that actually corresponds to the ID I have defined in Stripe as my billing plan. So this, this would be updated to be that ID that actually exists in Stripe. All right. So that's basically all we need to do. I've already configured my environment variables behind the scenes. I think one thing we do need to do next is just make sure that our migrations

Running Database Migrations5:35

I've already configured my environment variables behind the scenes. I think one thing we do need to do next is just make sure that our migrations are up to date because I didn't run those migrations when I initially installed Spark because typically I would run those for my Homestead VM. So let's go back to our terminal and I'm already SSH into this VM. So let's change to the demo directory and just run php artisan migrate to make sure that our database is created and all of Spark's tables are also created because you can see Spark creates nine or 10 tables here to store all of the default sort of Spark information, your user information, your team information, your API tokens and so on.

Uh, for example, I can change my name to something else and just update that and it's as easy as that. And this is all generated out of the box by Spark. So this is all stuff that you don't have to worry about things you don't have to code and it saves you weeks of programming. Now on the security tab, we have our typical update password form where I can do all of that business on our API tab. We can generate API tokens because remember in our SparkServiceProvider, we are saying that we want to allow an API. So that's what enables this tab.

Now, of course, from within the screen, I can also change my plans if I have multiple plans. So let's go ahead and go back into our SparkServiceProvider and let's define another plan here so that I can show you that feature. All right. I'm just going to copy this down and expose a $20 a month pro plan. And I'll give that sparkTest too, because I already have that defined in Stripe before I even started recording. So I know that's ready to go. All right.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟