DocTolly

DocTolly

Member Since 1 Month Ago

Experience Points 6,510
Experience Level 2

3,490 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 63
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.

14 Jul
4 days ago

DocTolly left a reply on Deleting Users Passport Token On Logout.

@d9705996 This was worrying me too. By default the tokens are long life (something silly like 100 years). Overriding the default token settings doesn't seem to change it either which was odd - also it seemed a bit poor practice to set a short token life (for example, if I later use access tokens for a mobile app).

I'm still looking into how I can generate a password grant via the login method (I think I just make a post request to the controller which issues them) More confusingly, is how I can pass that token to for the js app to use on it's access requests. (I don't think password grants are automatically passed into axios requests them the same way bearer tokens are).

I find it hard to believe I'm the only Laravel user who has faced this issue, so there must be something I have missed!

11 Jul
1 week ago

DocTolly left a reply on Deleting Users Passport Token On Logout.

@d9705996 Thank you for that. Sounds like password grant is more like what I need (which is a key only valid whilst the user is logged in on the Laravel part of the app).

@bobbybouwmann That's essentially what I ended up doing. Re declaring the logout method in the controller. I wasn't too comfortable overwriting the default logout method though

DocTolly left a reply on Deleting Users Passport Token On Logout.

@d9705996 thanks for your response. Out of Internet am I going about providing an api key to access my api end points in a sensible / reasonable manner?

DocTolly started a new conversation Deleting Users Passport Token On Logout.

Hello!

Thank you to the community for your continued support!

I am working on implementing API keys using Passport.

For now, the key will be consumed by a small app within my own front-end (for validating a user is logged in / can access the content). I am using Passport as it leaves room for expansion in the future.

When a user logs in, I issue them a new token using the authenticated function in the LoginController which, as we know, automatically gets fired after a user successfully logs in. (This works).

class LoginController .... {

    use AuthenticateUsers;

    protected function authenticated(Request $request, $user)
    {
        $token = $user->createToken('userToken'.$user->id)->accessToken;
    //more code
    }

When the user logs out, I want to revoke this access token.

I can see that I can override the method ::loggedOut($request), however I can't access the user details in this method as the user has been logged out, therefore $request->user() is null!

As with most problems I come across in Laravel - there is probably a simple solution that I don't know about yet! Does anyone have any ideas?

At the moment, the only solution I have thought of is creating a new logout method in the LoginController which deletes the token and then delegates to the logout() method in the Authenticable trait of the Login controller.

class LoginController ....... {

    use AuthenticateUsers;

    public function deleteTokenThenLogout(Request $request)
    {
    //Delete Token here

    //Delegate to the actual default logout method in the AuthenticateUsers trait 
        return $this->logout($request);
    }

Although at first glance, this seems sensible. It's actually really messy, because in order to declare a logout route which points to this method in the controller. I would have to delete Auth::routes from my routes file, and therefore manually declare all the other authentication routes, individually. (On reflection it would be nice if the Auth::routes() helper had an 'except' option!)

Does anybody have any advice on how to cleanly delete the token on logout please?

Am I even going around using Passport / API keys in the right manner?

30 Jun
2 weeks ago

DocTolly started a new conversation How To Modify Relationships Loaded Using With()

How could I modify a relationship loaded through the with() method. For example, if I wish to apply a presenter (hemp/presenter) to the staff relationship loaded here

$duties = $this->job->duties()->someRandomScope()->with('staff')->get();

I can easily apply a presenter to the duties:

$duties->present(DutiesPresenter::class);

How could I apply a presenter to the Staff relationship?

10 Jun
1 month ago

DocTolly left a reply on Error: Call To A Member Function BelongsTo() On Null

@SNAPEY - Even though $this->assignment does work for me (somehow). It sounds like you're saying it shouldn't be done like this anyway.

How would you recommend referencing a grandparent model

Its as if I need something like a belongsToThrough relationship

DocTolly left a reply on Error: Call To A Member Function BelongsTo() On Null

Hi thanks for your help. I found the problem which was I was calling an load function in a controller which had the models wrong in it (i changed models after making that controller).

FYI the $this->assignment relationship seems to work?

DocTolly left a reply on Error: Call To A Member Function BelongsTo() On Null

I'm still scratching my head over this, it's really not behaving as expected. Guidance appreciated.

DocTolly started a new conversation Distant Relationships Which May Or May Not Exist.

I feel there is something simple I haven't learnt. Maybe you guys can help? :)

Imagine this situation (I've changed model names to make them more understandable):

A team has many assignments #Assignments belong to one staff (or they don't belong to anybody - staff_id = null) #Assignments have many Tasks

I want to find out who the staff member is, from within the Tasks model.

Within Assignment model:

    public function staff()
    {
        return $this->belongsTo(Staff::class);
    }

    public function tasks()
    {
        return $this->hasMany(Task::class);
    }

The staff relationship won't work. Why is the assignment relationship null? Within Tasks model:

    public function assignment()
    {
        return $this->belongsTo(Assignment::class);
    }

    public function staff()
    {
        return $this->assignment->belongsTo(Staff::class);

    //Error: Call to a member function belongsTo() on null
    }