pilat

pilat

Member Since 2 Years Ago

Experience Points
21,270
Total
Experience

3,730 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
186
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 5
21,270 XP
Oct
29
2 weeks ago
Activity icon

Commented on Deploy Your Website

Can you explain why echo "" | before the php-fpm reload command?

Oct
17
1 month ago
Activity icon

Commented on Migrations 101

It looks to be "Nord" ( https://laracasts.com/comments/1448 ) They have it in VS Code as well ;-)

Oct
07
1 month ago
Activity icon

Replied to Service Container: A Proper Way To Rebind Service In Each New Job

Ok. Maybe, two simpler questions:

  1. How to unset (destroy, nullify) specific service? Like App::forgetInstance('Querty') (I saw this in stackoverflow, but couldn't find it in the SDK documentation for 5.8 probably, removed from framework?)

  2. Is there some kind of a "job ID", accessible from within deferred service provider? I'd like to check if there's an instance for current job and create new one only in case of "NO".

Oct
02
1 month ago
Activity icon

Replied to Service Container: A Proper Way To Rebind Service In Each New Job

Just came to my mind: sanitising would also be an issue For a sake of simplification, let say, I'll just cache it for one minute (so, theoretically, it can be rebind again even within one job, if it's started "between minutes"):

$epochMinute = intdiv(time(), 60);

# Caching/kinda singleton
if (! empty($this->instances[$epochMinute][$subdomain])) {
    return $this->instances[$epochMinute][$subdomain];
}

After some time, there will be quite many instances in the memory, and how do I know which ones are not used by any other jobs any longer (maybe, there's some very long synchronization right in the moment)?

Activity icon

Started a new Conversation Service Container: A Proper Way To Rebind Service In Each New Job

I have Laravel Horizon on my server, which means, in particular, that queue workers are long-running processes.

Then I have service providers that cache bindings ("semi-singleton", you name it). The code is like this:

public function register()
{
    $this->app->bind(MyService::class, function ($app, $parameters) {

            $subdomain = isset($parameters[0]) ? $parameters[0] : null;

            if (is_null($subdomain)) {
                return null;
            }

            # Caching/kinda singleton
            if (! empty($this->instances[$subdomain])) {
                return $this->instances[$subdomain];
            }

            $this->instances[$subdomain] = $this->performSomeLongInitialization($subdomain)

            return $this->instances[$subdomain];
    });
}

This works like a charm for the web requests, but in queued jobs I need to re-init MyService more often than I re-load horizon. Ideally, to re-init it in each next job. Is there some global identifier, like jobId or I don't know, which I could use in service provider to decide if I need to initiate the service again?

Jun
26
4 months ago
Activity icon

Replied to Gluing Up Socialite And A Stand-alone SPA

One idea: save user data under some unique "browser fingerprint" — the one, that can be collected by both backend (when handling authentication) and by SPA (when requesting user data).

This fingerprint should be:

  • the same for each consequent request within the same browser session

  • unique among the sessions (never repeated for another user)

  • (optional, but wanted) "collectable" from within PHP and JS code. I.e., Laravel gets request to '/login/facebook' — it can initiate the authentication procedure and then save the results under that "fingerprint" used as ID. Then, SPA wants to load user data, collected by Socialite: this is JS code, but it should be "able" to generated the same fingerprint for sending it to backend to deliver the user data.

Any ideas what can be used for this?

Activity icon

Replied to Gluing Up Socialite And A Stand-alone SPA

@BOBBYBOUWMANN - social_user is an object with some props (like, id, name, email) in its root, filled by Socialite driver (e.g., to ensure that certain props are always named the same, whatever provider is used) PLUS there is a 'raw' result of "get user info" request — this "raw result" is stored into 'social_user.user' and this is what I actually need in this place.

Concerning "everything in front-end": I've tried to use "OAuth Implicit" flow (browser only) for the authentication — this way I wouldn't need backend at all (at least for auth). But it didn't prove reliable, so, I decided to switch to "OAuth Authorisation Code" flow (browser + server-to-server) instead.

Anyway: I'm currently using cache (it could be database table just as well), but it's quite ugly: I pass cache key to the SPA via URL, then request user data, using this key from the URL…

Backend:

// app/Http/Controllers/Auth/LoginController.php

    public function handleProviderCallback($provider)
    {
        $methodName = Str::camel("get-{$provider}-user-data");

        /** @var array $user a structure of my own design =) */
    $user = $this->{$methodName}();

        $hash = md5("{$provider}.{$user['socialUserId']}");
        Cache::put("social_user.{$hash}", $user, now()->addHour());
        
        return redirect(config('app.spa_url') . "#{$hash}"); // config('app.spa_url') contains URL to the SPA 
    }
// routes/web.php

Route::get('social_user/{user_hash}', function ($userHash) {
    return response()->json(
        cache("social_user.{$userHash}")
    );
});

SPA:

// src/store.ts

  loadUser ({ commit, getters }) {
    const userHash = location.hash.substr(1, 32);
    const url = `${getters.backendUrl}/social_user/${userHash}`;

    axios.get(url).then(
      response => commit('DO_AUTH', response.data),
      error => // ...
    )
  }

What I don't like here — is that cache key needs to be in the URL when user in on SPA page.

Jun
25
4 months ago
Activity icon

Started a new Conversation Gluing Up Socialite And A Stand-alone SPA

Hi, my project is consisting of two separate apps:

  1. Laravel-based back-end

  2. An SPA, "living" separately and built using Vue CLI.

Now, I'm trying to implement Login via Facebook.

There are two routes, on the backend:

Route::get('login/{provider}', 'Auth\[email protected]');
Route::get('login/{provider}/callback', 'Auth\[email protected]');

So, if I click a link like: /login/facebook — I'll get logged into Laravel in the result.

Now, I need a way to pass user data to the SPA (which is NOT a part of Laravel). Here's what I've tried so far:

Laravel's Login controller (it's callback action):

// app/Http/Controllers/Auth/LoginController.php

   /**
     * Obtain the user information from Social provider.
     *
     * @return \Illuminate\Http\Response
     */
    public function handleProviderCallback($provider)
    {
        $user = Socialite::driver($provider)
            ->fields([ 'id', 'name', 'email', 'picture', 'link', 'friends' ])
            ->user();

        session([ 'social_user' => $user ]);

        return redirect(config('app.spa_url') . '#authenticated');
    }

Then, there is such code in the SPA:

// src/pages/Home/Home.vue

  created () {
    this.$store.dispatch('loadData')

    if (location.hash.indexOf('authenticated') !== -1) {
      setTimeout(() => this.$store.dispatch('loadUser'), 1000)
    }
  },


// src/store.ts

  actions: {

    loadUser ({ commit, getters }) {
      let url = `${getters.backendUrl}/social_user`;

      axios.get(url).then(
        response => commit('DO_AUTH', response.data.user),
        error => // ...
      )
  }

Finally, here's the code for serving /social_user request in the Laravel:

// routes/web.php

Route::get('social_user', function () {
    return response()->json(session('social_user')->user);
});

Note: this is WEB.php, so, the session should be picked up. And it actually does, when I open /social_user URL in the browser. In the Ajax request, however, it's always empty?

So, I have those questions:

  1. Why the session variable is empty, but only if it's Ajax request?

  2. Are there any other ideas on how to pass user data from laravel to SPA?

One note in regards to #2: authorisation should be handled via redirects (just like Socialite does it). First, I've tried to implement "OAuth Implicit Flow", using popups — but this method didn't work well on mobiles. In particular, popup is not always (no in all browsers/OSes) closed after the access token is retrieved, so, the user thinks the authentication has failed.

May
22
5 months ago
Activity icon

Replied to Feature Tests Do Not Work (404)

@DEVFREY - > You don't need the /public at the end :)

Sorry, this didn't help.

@diegoaurino

The test suite will not understand that it needs to follow this long path ( http://MYSITE_REPLACED.info/back/public/ ) to hit the API endpoints

Ae you saying there is no way, as long as my Laravel application is acessed in a subfoler of site? Ok, I think I can live with that. Just wanted a confirmation.