Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Login/Register Screens and Calling API

Premium
16 min read

Let's start implementing features into our Application:

  • Setting up API URL
  • Setting up custom middleware to check users' Auth status
  • Registration via API
  • Login via API

By the end, we should have a working Login/Registration system.


Setting Up API URL

First thing we need to do is add our API URL to our .env file:

.env.

# ...
 
API_URL=http://nativephp-events-app-api.test/api

Of course, we should never load the .env file in our code, so let's set up a config file for this:

config/services.php

// ...
 
'slack' => [
'notifications' => [
'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'),
'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'),
],
],
 
'api' => [
'url' => env('API_URL'),
],
 
];

Now, we will be able to get our API URL by calling:

config('services.api.url')

Creating Custom Middleware

Now we have to think about our sessions. The typical auth middleware won't work here, as we are authenticated via token. So let's create a new one:

php artisan make:middleware ApiTokenExists

And inside it, we'll add:

  • A check to see if we have token set in our session
  • An API call to load the user Profile

The Full Lesson is Only for Premium Members

Want to access all of our courses? (31 h 16 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…