Member Since 4 Years Ago


Software Engineer, Lead at SoftLayer/IBM

Experience Points 1,970
Experience Level 1

3,030 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 31
Best Reply Awards 0
Best Reply
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement


    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement


    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

16 Feb
1 year ago

philthathril left a reply on Register Middleware Via Service Provider

Sorry if this is out of scope of the original question, but the above answers lead me to my solution of accessing previously-set properties in the terminate() method of my middleware, so I wanted to share what I did.

Using L5.5, I did not have to call $kernel->prependMiddleware() or $router->middleware() manually. I set my global middleware in the kernel.php along with all the other ones. Then in the AppServiceProvider I created a singleton of the middleware. The code starting with my middleware...

// Middleware.php
use My\Lovely;

class Middleware
    protected $keepMeAround;

    public function handle($request, \Closure $next, $guard = null)
        $this->keepMeAround = "I'm here!";

        return $next($request);

    public function terminate($request, $response)
        echo $this->keepMeAround; // I'm here!

And then the kernal...

// kernel.php
class Kernel extends HttpKernel
    protected $middleware = [

And finally the AppServiceProvider...

// AppServiceProvider.php
use My\Lovely\Middleware;

class AppServiceProvider extends ServiceProvider
    public function register()
        // @see
        // Manually add this as a singleton so that when the terminate() method
        // is called on the middleware, we'll be using the same instance of
        // the originally-instantiated My\Lovely\Middleware.
        $this->app->singleton(Middleware::class, function ($app) {
            return new Middleware();

If the instructions found at are confusing to you, hopefully this will save you a few minutes.


08 Feb
1 year ago

philthathril left a reply on Laravel Passport "unauthenticated" Error

I, too, was getting "Unauthenticated." with each request using Postman after having successfully received a valid access token. After banging my head against the desk for a while and throwing everything at the wall to see what sticks, the thing that worked was updating the config/auth.php defaults.guard value:

    'defaults' => [
        // 'guard' => 'web',        // <-- commented this out
        'guard' => 'api',           // <-- made this the default
        'passwords' => 'users',

And then the first request to GET /oauth/personal-access-tokens with the appropriate access token Authorization header worked.

At this point, my whole application is just an api, so defaulting the guard to api should be good. Hopefully this will help someone else.

27 Nov
1 year ago

philthathril started a new conversation Unserializing Model Template In Queue - ModelNotFoundException

Hi. I have a queue job that is supposed to act upon a populated model template (but not yet saved in the database).

public function doSomething()
    $somethingGreat = new My\Great\Model();
    $somethingGreat->pizza = "is fun";


Upon dispatching that job, I get the following exception:

Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [My\Great\Model]  in /home/vagrant/hello/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:329

Stack trace:
#0 /home/vagrant/hello/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(54): Illuminate\Database\Eloquent\Builder->findOrFail(NULL)

I understand "why" it's failing, but I'm more curious if there is a way to unserialize a template model that won't try to be pulled from the database from SerializesAndRestoresModelIdentifiers::getRestoredPropertyValue()?

I would think that method would first check to make sure id is not empty before trying to query on it, but it doesn't. How do you propose getting around this? Am I missing something obvious?


08 Jul
3 years ago

philthathril started a new conversation Queues In L5.1 Vs Commands/handlers In L5.0

Hi. In my app that I've so far built in L5.0, I use commands and handlers for all my business processing - add user, add idea, follow project, etc. I currently have my structure setup as:

app/Domain/<domain type>/Commands/
app/Domain/<domain type>/Handlers/

I chose not to go the direction of the commands being self-handling because I really see those as data objects and nothing else. The handlers actually contain all the logic.

However, in L5.1, the Queue has replaced the Command Bus, and the examples in the docs show the Jobs as being self-handling. Now, I'm sure that they could probably not be that way (by not specifying SelfHandling for the Job).

What I want to know is... which way is encouraged - self-handling vs. separate handlers? And does L5.1 encourage one? I'm leaning towards keeping separate handlers, but would appreciate community feedback.


18 Jun
4 years ago

philthathril left a reply on Restricting Pieces Of A View

@janareit Thanks for that suggestion. I like the cleanliness of that approach. I'll investigate that further.

15 Jun
4 years ago

philthathril left a reply on Restricting Pieces Of A View

@tuneless At this point, I won't be using a JS framework for the frontend UI, so I'm stuck with blade templates at this point. And from my example, I think we're talking about the same thing - a "child" view is really a partial. It only contains a small piece to display, and of course can be included from wherever.

philthathril started a new conversation Restricting Pieces Of A View

Let's say I have blade template with various pieces of markup on it. Some of the content may be seen by everyone and other content may only be seen by users with permission/role A and other additional content by users with permission/role B. I see ACL as deciding what entry points are accessible into the application, not about what individual items should I render on the page. Is this a faulty view of ACL?

What is the best way to restrict view items?

Option 1: quick and dirty

@if (user has access to role A)
@elseif (user has access to role B)

That just feels dirty and will allow the templates to start looking really ugly really quickly, even if the individual pieces are @include()-ed. It also doesn't appear to be scalable as more roles are added.

Option 2: individual templates determine their own access

This is similar to the above, except that the permissions are in the individual blade templates. If the user does not have access, then that whole sub template is bypassed.

// parent view

// some/child1 view
@if (user does not have access)
    // return

// some/child2 view does similar check

Option 3-n. Whatever the fine minds at laracasts can educate me on.

Thanks for your input in advance.

05 May
4 years ago

philthathril left a reply on Choosing The Appropriate HTTP Error Code

Thanks for the quick reply. I, too, always generally thought something was really wrong if I got a 500 response, but I was having trouble finding what fit the best when looking over the set of codes. But now that you point out 403, that does look like what I am looking for.

04 May
4 years ago

philthathril started a new conversation Choosing The Appropriate HTTP Error Code

Hi. I'm trying to determine what error code(s) I should be using for various exceptions in my app. For example, if the user goes to delete some object, except that object cannot be deleted at this point (due to business reasons), what response code would I use in this case?

200? 400? 500? Some other code?

I tend to think 500, but I wasn't sure if it's the most appropriate. Any thoughts would be appreciated. Thanks!

23 Apr
4 years ago

philthathril left a reply on Laravel 5 AJAX TokenMismatchException

I had an issue on a different framework (cake I believe) where I was sending in a bunch of ajax requests at once and some were failing. It was random on when they would succeed and fail. I believe we increased the number of allowed connections that apache would receive at once, and that seemed to fix the problem. (It's been a minute, so I think that's the solution we came up with.)

Anyway, it may not be framework or javascript related - check your server configs too! Hope that helps.

16 Apr
4 years ago

philthathril left a reply on Please Help Me Stop This Layout Insanity

That seems like a very idealistic solution. While I agree that would be fine in some cases, sometimes I want a view to be accessed within a modal popup or on a page by itself. Since the page already defines all the html, I don't see a reason to duplicate it in javascript.

philthathril started a new conversation Please Help Me Stop This Layout Insanity

In my template, I want to use a different layout based upon the request being ajax or not. Currently, I have a mean hack to get it working, but I'm not proud of it. Can someone please let me know the "proper" way of switching layouts?

// controller
    public function __construct()
        View::share('layout', Request::ajax() ? 'ajax' : 'default');

// blade template


19 Mar
4 years ago

philthathril left a reply on Relationships With Pivots

Ok, this won't help anyone in the future, but I decided to change up my relationships. Now I have a direct relationship between users and projects instead of going through talent_user.

- id
- project_id
- user_id

And since users have a relationship to their own talents, I can just grab that data when needed...

18 Mar
4 years ago

philthathril left a reply on Relationships With Pivots

I found this as well, which is what I want to accomplish:

Unfortunately, looks like the current available relationships are just not setup to support this. Okay, that's fine. Is there a clean and easy way to set this up using other methods?

philthathril left a reply on Relationships With Pivots

Thanks for the suggestion, @dfaux, but I don't think that answer helps me in my situation. His suggestion seems to be a fairly straight-forward example of the belongsToMany pivot design.

Through my searches, I ran across, which is what I based my code off of above. It just doesn't seem to be working for me. I will keep chugging along, but any more thoughts would be appreciated.

philthathril started a new conversation Relationships With Pivots

Ok, bear with me while I setup these relationships. I have these tables:

users: User
- id

talents: Talent
- id

projects: Project
- id

talent_user: UserTalent (pivot class)
- id
- talent_id
- user_id

project_members: (No class, many to many join table)
- id
- project_id
- talent_user_id

I want to establish these relationships:

Find all projects associated with user:
- users -> talent_user -> project_members -> projects

Find all users associated with project:
- projects -> project_members -> talent_user -> users

I have these classes on my User class (and something similar on Project) as well:

// on User
    public function projects()
        // this is the bad relationship because talent_user_id is referencing the "user id" and not the "user talent id"
        return $this->belongsToMany('Project', 'project_members', 'talent_user_id', 'project_id');

    public function newPivot(EloquentModel $parent, array $attributes, $table, $exists)
        if ($parent instanceof Project) {
            return new UserTalent($parent, $attributes, $table, $exists);
        return parent::newPivot($parent, $attributes, $table, $exists);

Am I able to establish the desired relationships (listed above) using something similar to the above code? If not, what are my alternatives? Are you able to (and would it even be recommended) to write queries to create the relationships?

Thanks in advance!

13 Mar
4 years ago

philthathril left a reply on Attaching Authenticated User To New Object

@radbonev Thanks for the feedback. I do like that option. I suppose I could still use the named parameters feature of commands/dispatchFrom to do......

$this->dispatchFrom('My\IdeaCommand', $request, [
    'user' => Auth::user()

From what I've read/saw, laravel will attempt to automatically associate the correct key to the parameter in the command, allowing me to do.....

public function __construct(User $user, $otherFields,...)

I'll try that and see if it works. If not, I'll use the dispatch() call directly instead.

(FYI, I just made up the command name for this question - the real commands I use are much more descriptive.) :)

12 Mar
4 years ago

philthathril started a new conversation Attaching Authenticated User To New Object

I have 2 models - user and ideas. A user may have many ideas. When creating a new idea, I need to attach the user_id to the idea object from the authenticated user. I am creating the ideas by dispatching a command from the controller. Since I want the command to remain as dumb as possible, I don't want to add the user_id from the command. Also, it seems as though adding the user_id from the controller is clunky. What are recommended practices here?

Do I really want to do this?

// controller
$this->dispatchFrom('My\IdeaCommand', $request, ['user_id' => Auth::user()->id]);

I also don't really want to do this:

// command
public function __construct($title, $description)
    $this->user_id = Auth::user()->id;

// or even the handler:
public function handle($command)
    $command->user_id = Auth::user()->id;

Any tips would be appreciated. Thanks!

03 Mar
4 years ago

philthathril left a reply on Class Naming Conventions

Thanks for the input. I've always been an advocate for not being redundant when naming classes and methods. For example, if I'm in a User class, I would not do:

public function createUser() {...}

I would do:

public function create() {...}

However, I think for this particular case, I am going to be redundant in the class name despite the path which already provides the context of the class for several reasons:

  1. Easier grep'ability - I would like to be able to search for RegisterUserCommand in my codebase instead of needing to specify the full path to determine which RegisterCommand I'm looking for.
  2. Ability to immediately recognize the context of the class. When I see RegisterUserCommand I know immediately and exactly what it's referring to. When I see RegisterCommand (which I haven't aliased during the import), I now have to examine the surrounding context or skip to the top of the class to determine what it's referring to.

Like others have pointed out, it's all opinion! Heck, I may change my mind 6 months from now when I'm a thousand classes into the project. :P Thanks again all.

02 Mar
4 years ago

philthathril started a new conversation Class Naming Conventions

Hi. I know this is probably totally subjective, but I wanted to get some opinions about naming classes. Specifically, I'm curious as to how I should name my commands and handlers. For example, I currently have this:

''' app/Domain/Users/Commands/RegisterCommand app/Domain/Users/Handlers/RegisterCommandHandler '''

Now, I don't explicitly say RegisterUserCommand because I'm already within the context or domain of Users, so it just seems redundant. And if I need to use that class, I can always alias it if needed:

'''php use MyDomain\Domain\Users\Commands\RegisterCommand as RegisterUserCommand; '''

With that said, if I don't alias the class and I instantiate the class directly (instead of using dispatch(), then I lose some readability:

'''php new RegisterCommand(...); '''

Just looking at that piece of code, you don't know what's being registered. So, any thoughts on the direction to go or is it purely subjective?


23 Feb
4 years ago

philthathril left a reply on Self Handling Commands Or Separate Command Handle Class?

I read somewhere - don't recall where - that having the handler in the command may not be a good design because it's mixing concerns. The argument was that the command is just a data object while the command handler contains the logic that acts on the data. I tend to agree with this approach even though it does double the file/class size. Like everything else, I think you have to do what works for you in your situation. I do believe it's quite possible to over-architect a solution, so just find the solution that works best for you.

philthathril left a reply on Models, Repository Pattern And Eloquent

Thanks to all for the great input and conversation thus far. I was definitely hoping for a black and white answer, but I can now clearly see that it's only a bunch of grey because there is no single "right" way to code a solution. As a newbie to laravel, this is frustrating, but it does get me to think a lot about the direction I want to take my app(s).

FWIW, I believe the direction I will go is to use a combination of repositories and the command bus. This will allow enough abstraction from the controller, which will help keep all my business rules and complex logic silo'd. Using the command bus is a good solution when using L5, but I'm curious as to what solution I would use outside of L5 - meaning from a framework-agnostic perspective?

Also, I still haven't completely wrapped my head around what "services" are and how I'd use them. What sort of logic do they contain? Business? App? To be clear, I'm not referring to service providers....... unless they are actually the same thing and I'm just getting caught up on terminology.

18 Feb
4 years ago

philthathril left a reply on [L5] Command Not Mapping Snake Case

@JeffreyWay What do you mean it's been removed? It appears to still be supported in the docs: Also, what part of it is a security risk?

16 Feb
4 years ago

philthathril left a reply on Models, Repository Pattern And Eloquent

@jekinney Yes, it does map your database columns to object properties. However, if I'm wanting to add a layer of abstraction so that I can guarantee a structure - even if the backend object changes - then I don't really want to rely on that implementation. Or, if I don't want to couple my results with my business models, then I'd want to use an agreed-upon contract (DTO)..... I think. Am I over-thinking this? I'm wanting my application to use a restful design, so I'm being cautious about tying my business models to my api results.

philthathril left a reply on Models, Repository Pattern And Eloquent

@JeffreyWay As of right this moment, my current project is not that large, but I'm wanting to develop it in anticipation that it will grow large. I want to decouple my controllers and models, not so that I can swap out the persistence storage (because that will probably never happen), but because I want it to remain flexible and easily testable.

I've seen some examples where people define the structures that come back from repositories - essential data transfer objects. But I've not really seen examples of this on the laravel site or this site. Does anyone have opinions for whether repositories return DTOs so that you're truly committing to a specific contract instead of just what eloquent returns? Obviously, this means that you'd always have to convert all your returned objects to these custom objects, but I've written a mechanism before that's done that.

Thanks to all for the great input so far!

philthathril left a reply on Models, Repository Pattern And Eloquent

@deringer Thanks for the quick reply. I have actually read that article (several times to wrap my head around it). I think you touched upon something that may help me understand what the controller knows. Lemme confirm. Basically at the controller level, should the only thing it knows about the object returning from the repository is the data structure?

Also, in Shawn's post, he provides this example:

$member = Member::register($email, $password);

In this case, is Member not the model? If it is the model, isn't it breaking the pattern?

Also, he mentioned specifically that the repository shouldn't have "create" functionality because it's just a collection, so how is that handled? He gave an example of possibly using a factory, but would that be on the model or the repository or elsewhere?

15 Feb
4 years ago

philthathril started a new conversation Models, Repository Pattern And Eloquent

Hi. Long time PHP-developer, but fairly new to Laravel and using the repository pattern. I have read plenty of articles, conversations and blogs about repositories. What I just don't seem to understand is when not to use them.

For example, I have a User model with a UserRepository interface and an EloquentUserRepository implementation of that interface.

// model
User extends Eloquent {
    public function someMethod() {...}

// controller
$user = $this->userRepository->findByUsername(...);

What I don't understand is if the User model is really an Eloquent model, but I'm abstracting with an extra layer (my repository), is the above call to someMethod() breaking that pattern? If the repository is essentially hiding the "ORM" portion, should I be calling Eloquent/ORM-related methods on model?

Any tips on how to interact with my models and repositories would be appreciated.