This episode is for members only

Sign up to access "Laravel Subscriptions" right now.

Get started
Already a member? Sign in to continue
Playing
18. Displaying invoices

Transcript

00:00
Okay let's go ahead and build out a new section on our subscription page to list out invoices. Okay so the first thing that we're going to do is just head over to where we have all of our
00:10
partials. I'm going to go ahead and grab any of these and just create out a new one and of course that's going to be for our invoices. Let's create that out and we'll just go ahead and paste in the content of any of these and go ahead and give this a name and here we'll just say these are your invoices. Okay so down here we are not going to need a form so let's go ahead and just get rid of
00:34
this and in here we're going to go ahead and list through all of our invoices. Okay let's add this to our index page so let's grab out all of the code for this section and let's put this just down here at the very bottom and we'll go ahead and include the invoices partial. Okay if we head back over we should now see our new invoices section and now we need to figure out how we
01:00
are actually going to get these invoices. So we're going to load these on the same page as everything else so that will be under our subscription controller. Of course at this point because we are sending quite a bit of data down here for each of the sections that we're rendering you might want to do this on separate pages or if you're using something like livewire you could
01:21
create separate components for each of these sections which all load their own data. Okay let's go ahead and figure out how to grab invoices regardless of how you want to set this up and once again as you would imagine we're going to go ahead and use the user which is the billable entity. We can then go ahead and very simply use the invoices method to grab out a list of our
01:44
invoices. Before we go ahead and pass these down let's just kill the page up here and dump these out just to see what this gives us. Let's give the page a refresh and we get a collection and each of these now has an invoice model associated with it. In this case it's an invoice object which is pretty much just a decorator for all the data that comes back from Stripe. Okay so we already saw this
02:09
earlier because we used the upcoming invoice method to grab the upcoming payment. Now we just have a collection of all of the same things so we can just iterate over these, display the details associated with them including the formatted amount and we're good to go. So let's go back over to our invoices section and start to iterate through these now. So we'll do a for each loop on invoices and then
02:35
we'll go ahead and just figure out how we're going to style these up. So let's just create a container for each of these and it might actually be better to set this as an unordered list. Again you can figure out the styling and how you want to display these for yourself but let's use an unordered list and a list item for now. Okay so let's create out a strong tag here. This is going to be the invoice
02:55
date so we already know how to do this from earlier. Let's grab the current invoice and we'll grab out the date and that gives us a carbon object so we can just say to date string in there. Let's take a look at this on the page and see what it looks like and yeah let's just have a look here. Yeah that was named incorrectly. Let's try that again and if we scroll down there we go we've got the
03:16
date of each of the invoices which of course in our case is all from the same day. Okay so what we can do now I'm not going to style this up properly I'm just going to go ahead and put all of the details in line here. We're going to output the invoice total which we've already seen and then just after this we're going to add a link which is going to go through to download the invoice. We'll
03:36
look at that in the next episode. So we'll just add in a hash there for now and let's style this up with some text indigo let's say 600 or 500 and we'll just about leave it like that for now. So there we go we've got a list of all of our invoices now we know exactly how much the total was and the date for each one. Let's go over to the next episode and look at how we can download these.
26 episodes2 hrs 38 mins

Overview

Learn to start accepting subscriptions with Laravel and build a solid foundation for your next application. In fact, it’s exactly how we do things here on Codecourse!

Even if you’re completely new to Laravel, by the end of this course you’ll have a platform where customers can purchase subscriptions and gain access to restricted areas of your application.

We’ll also cover managing subscriptions, cancellations, invoices, giving customers trial periods — and more.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!