Introducing LoginLink package0:00
Laravel LoginLink is probably one of the smallest packages on our list, and it's from a company that you might know. Sparcy. And yeah, there will be some more Sparcy packages throughout this video. But now let's back to Laravel LoginLink. So we are here on the repository for the Laravel LoginLink package. And let's skip the description here and let's go right to the code example. So we're going to provide some login links like this here. And then on our login form, we can show those links like mentioned here. And then the idea is that we just click the link and get automatically
And then on our login form, we can show those links like mentioned here. And then the idea is that we just click the link and get automatically locked into the application. And it sounds pretty trivial, and it also is, but it saves you a lot of time. Because even if your email and password for local development are pretty simple, you have to do this all of the time, log in, and yeah, I found that with this package, this is so much faster. So let's give it now a try together. Let's copy this here in order to install it. All right, let's install this package.
Installing and configuring1:07
Let's copy this here in order to install it. All right, let's install this package. I have this already prepared here. Let's run this. All right, and let's also publish the config file like this. Here we go. Let's take a look. I think this should be the config file. Yeah, we can go through this real quick together. So we can define allowed environments.
Yeah, we can go through this real quick together. So we can define allowed environments. Some more functionality, more interesting is if we're using the base main User model and Level, which we do, so we don't have to change this here. But if you do, you can. Yeah, you need to update this here. All right, then when we talk about our application, let's also take a look at what we got here. So this is a Level chat stream application.
Adding login link view1:55
let's also take a look at what we got here. So this is a level chat stream application. So this means authentication is also provided here. So this is what our typical chat stream login page looks like. And here we want to provide now a new link. So this means we're going to our login.blade.php file, which you can find on the resources/views. And then here we have it. And right above our form, we are now going to add a first link. So let's take a look how we're going to do this.
And right above our form, we are now going to add a first link. So let's take a look how we're going to do this. Let's scroll down here. So here's the most basic example, which we also want to do by just providing the component without any more details. So let's put this in here. And let's also take a look at our database first, which we have here. So as you can see, we have a few Users already here.
Logging in default user2:39
which we have here. So as you can see, we have a few Users already here with some fake dummy data here. And the idea now with this package is if we don't provide anything, this component will log in with the first User from the database. So in this case, this should be Dimitri. Let's give it a try. Refresh. We should see the link here. By default, the label, the text is developer login.
Refresh. We should see the link here. By default, the label, the text is developer login. Let's click it. All right, seems we're logged in. Let's give it a look. Yeah, here we go. Dimitri is now logged into application. And yeah, this was pretty fast and easy. Let's go back. Log in, try again.
Logging in by email3:14
Let's go back. Log in, try again. Yeah, super simple and super convenient. But of course, you ask, yeah, but maybe you don't want to be logged in with the first User, maybe with a specific User. All right, yeah, we can do that as well. So if we go back to the database and say, let's say we want to log in with Rhys, so we can copy his email address.
let's say we want to log in with Rhys, so we can copy his email address. And what we can do here is we can provide an email. And what this does, it looks for the User with this email address. And if this is given, then we're going to log in with this User. All right, let's get in here. Try it again. And we should see now that we're now logged in with Rhys.
Creating role-based links3:49
Try it again. And we should see now that we're now logged in with Rhys. Yeah, so this was also working. Perfect. But there are a few more things that we can do. When we take a look at our database here, we can see that we also got a role for specific roles for user. The ones that we currently have are all employees, but there are maybe others like an admin.
The ones that we currently have are all employees, but there are maybe others like an Admin. So often what I like in my application, I want to log in with different roles for this application because then these different users probably have different permissions and you can test this very easily. So I'm going to create now two new links which will also create new users. So the first one should be an admin email address.
which will also create new users. So the first one should be an admin email address just so that we know that this is an admin. And we also want to define user attributes here. And the one which we are interested in is the role. So let's set the role to admin, which is a role in our system. Let's also make this a little bit cleaner. All right. And let's also give this a label.
All right. And let's also give this a label. And let's say this is called log in as admin User. All right, let's take this link here and let's create another one. And this one we want to log in as employee User. Let's also use a new email address here and the role should be employee. All right. If we now take a look,
All right. If we now take a look, we now log out here and take a look here. Again, we now see that we have two links here. The first one is for logging in as an admin user. Let's try this out. We have now Imogin Keen. Let's take a look at our database. Let's refresh. We can see that this Imogin user,
Let's refresh. We can see that this Imogin user, this new user with the name Imogin Keen has the role admin and our new email address. And if we log out and try the same now with our employee user, let's check out. We have now Cassidy. In our users table, we also have now a new user,
In our users table, we also have now a new User, Cassidy, with the role employee. So as you can see, this is very convenient to add links to your login form to make it as quickly as possible to log into your application while developing and using the correct users, using a given one if you want to or create a new one with some specific data.
using a given one if you want to or create a new one with some specific data that you can define yourself. Let's break down what we just learned. Level login link helps you to log into your application, but way faster. I'm going to use this package whenever I need to log into an application. Thank you. Spasib.
Thank you. Spasib.
