Playing
02. Setup with Pest

Episodes

0%
Your progress
  • Total: 4h 36m
  • Played: 0m
  • Remaining: 4h 36m
Join or sign in to track your progress
01. Introduction and demo
4m 49s
0%
02. Setup with Pest
4m 2s
0%
03. Building the user teams relations
6m 5s
0%
04. Creating a personal team when registering
6m 3s
0%
05. Leaving all teams when an account is deleted
3m 55s
0%
06. Tracking the current team
4m 50s
0%
07. Showing team details in the UI
2m 55s
0%
08. Switching to another team
7m 24s
0%
09. Authorising team switching
6m 53s
0%
10. Updating a team name
10m 48s
0%
11. Basic roles and permissions setup
5m 26s
0%
12. Team roles and permissions middleware
9m 18s
0%
13. Authorising current team updates
3m 43s
0%
14. Testing team permissions through HTTP requests
3m 58s
0%
15. Leaving a team
10m 50s
0%
16. Displaying team members
8m 42s
0%
17. Making team members look better
5m 3s
0%
18. Removing a team member
15m 18s
0%
19. Preventing self removal from a team
4m 7s
0%
20. Storing invitations
13m 31s
0%
21. Validating invitations
6m 38s
0%
22. Authorising team invitation creation
6m 22s
0%
23. Displaying invitations
3m 16s
0%
24. Revoking invitations
12m 46s
0%
25. Sending an invitation email
13m 6s
0%
26. Accepting an invitation
12m 22s
0%
27. Displaying a modal to change a member’s role
10m 31s
0%
28. Updating a member’s role
9m 5s
0%
29. More authorisation and checks for role changing
10m 14s
0%
30. Fixing up the email sending test details
49s
0%
31. Fixing and validating email addresses for invites
1m 32s
0%
32. Tidying up @can directive checks
3m 25s
0%
33. Detaching roles when removing users
5m
0%
34. Adding an extra layer of protection to the team middleware
6m 35s
0%
35. Getting related models through teams
5m 37s
0%
36. Building a helper to access the current team
10m 47s
0%
37. Getting all related models through all teams
7m 15s
0%
38. Creating new teams
13m 7s
0%

Transcript

00:00
Let's start things out by getting a fresh Laravel project set up and make sure that we can run tests. We're going to be writing tests for each of the features that we implement throughout the course. Of course, this is optional if you just want to follow through to grab the knowledge, but we'll be doing that pretty much the end of each episode.
00:17
Okay, let's get a project set up here. So we use the Laravel installer and let's go ahead and create this out and call this Laravel Teams. Okay, so we're going to be using a starter kit here. You don't need to. This functionality is pretty much detached from anything within the starter kit.
00:33
So let's go ahead and choose Laravel Breeze, which is the most simple. And we're just going to be building this out with Blade and Alpine. We won't be using a lot of Alpine, but we'll keep this really simple. And then if you want to transfer this over to Livewire or something like Inertia later,
00:49
you can use what you've learned to do that. Okay, so we don't really care too much about dark mode support. We're going to choose PEST as our testing framework. You can choose PHP unit if you prefer and let's just wait for this to run through.
01:00
Okay, so we'll go ahead and choose MySQL as our database driver and we'll go ahead and run the default migrations and also create that table as well. And that's all done. So let's go and cd into the Laravel Teams directory that we've just created and we'll go ahead and open this up in our editor.
01:17
Once this is open, the first thing that we're going to do is just make sure that this is working in the browser. I'm using Laravel Herd here. So let's just give this a refresh and there we go. We should be able to go ahead and register an account here. So let's just go ahead and create one out.
01:33
We're going to spend the majority of the time actually in the application and we're good with our Laravel application. Now we want to make sure tests are set up working nicely. So if you are new to Laravel, when we chose the PEST feature,
01:47
this will have created a couple of tests in here. Now Laravel Breeze comes with authentication functionality. So we've got a bunch of auth tests in here already and we have a profile test which deals with the profile section of Breeze.
02:01
Now just to keep things simple throughout the course, I'm going to go ahead and get rid of the profile test and I'm going to get rid of all the auth tests in here and just keep these two example tests. In fact, we're not going to be really writing any unit tests.
02:14
Most of these are going to be feature tests, but we want to make sure that we can actually run through these properly. Now by default, when we create our Laravel application, the phpunit.xml file, if we just take a look at this,
02:27
has the database connection that we want to use and the database that we want to use commented out. What this means is if we were to hop into the command line and run PEST, what that's going to do is it's going to use the database that we have configured
02:41
over in our environment file and that's really not what we want to do because when we're seeding fake data to test everything, this is just going to end up overwriting
02:51
or adding to the data that we have in our main database. So all we really need to do here is just uncomment the database connection. We can set this to SQLite. That's fine. And the database is just going to be an in-memory database as well.
03:05
So now we can comfortably go ahead and run PEST and we should with these two example tests get green. So let's just pull this up a little bit and we'll see what we are working with and there we go.
03:16
So we've got the example unit test. That's green and we've got the example feature test that is green as well. If we just take a look at these tests, this is how we're going to be writing our PEST test out.
03:27
The very simple feature test just hits the homepage and just make sure it works. Now we don't need this. We're going to be writing these from scratch so we can get rid of this and the example unit test just expects that the value true is true.
03:40
So again, we can go ahead and get rid of this as well. So we will be making a couple of modifications to PEST, but if you're at this point where you can run your tests and they pass, you're good to go
03:49
and you can follow along with writing the tests if you want to. So we have a fresh layer of our application set up. We can write and run tests. Let's head on and build out the rest of this team's functionality.
38 episodes4 hrs 36 mins

Overview

Need team functionality in your Laravel application? Let’s build it from scratch.

We’ll cover the basics of creating teams, switching between them, sending secure team invites by email, and managing team members.

Powering everything will be roles and permissions for each member, with the ability to switch roles directly from your team dashboard.

Once you’re done, you’ll have mastered team functionality in Laravel.

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

Episode discussion

No comments, yet. Be the first!