I've been perusing the code for Laravel Spark both for inspiration and to see how Taylor Otwell writes his application code. One class that took my special interest was the API\InvitationController.

Here are its dependencies.

use Illuminate\Http\Request;  
use Illuminate\Routing\Controller;  
use Laravel\Spark\Contracts\Repositories\TeamRepository;  

Notice that the only repository dependency for the InvitationController is TeamRepository. So, how do we get an Invitation result when it is not specified as a dependency above? I have added inline comments to make it clear.

/**
 * Get the invitation for the given code.
 *
 * User to display coupon during registration.
 *
 * @param  string  $code
 * @return \Illuminate\Http\Response
 */
public function getInvitation($code)  
{
    // Get the class of the user model 
    // from config/auth.php
    $model = config('auth.model');

    // Get the class of the invitation 
    // model from the user model relationship
    $model = get_class((new $model)->invitations()
        ->getQuery()
        ->getModel());

    // Query the invitation model
    $invitation = (new $model)->with('team.owner')
        ->where('token', $code)
        ->firstOrFail();

    if ($invitation->isExpired()) {
        $invitation->delete();

        abort(404);
    }

    $invitation->team
        ->setVisible(['name', 'owner']);

    $invitation->team->owner
        ->setVisible(['name']);

    return $invitation;
}

While this is an interesting technique to avoid a use statement (and maybe another repository injection), it takes three lines to figure out what the invitation model is. In the end, the code did get the job done. However, I wonder if it would've been clearer to inject an InvitationRepository to make the code more readable in the Controller (even a use statement for the Invitation model).

I must say that the visibility rules for the model relationships are very cool. This makes it easy to identify exactly what will be returned in the relationship json for this API controller.