jakeharris

jakeharris

Member Since 5 Years Ago

Experience Points 2,935
Experience Level 1

2,065 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 65
Lessons
Completed
Best Reply Awards 2
Best Reply
Awards
  • 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

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    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.

08 Jun
2 years ago

jakeharris started a new conversation Return Complex Data Type Using Decorator Pattern

I'm looking to do something I can best describe as a decorator pattern that returns an collection of results, though I am open to any more suitable alternatives.

I'm working on a sports statistics site for which I've created a handful of calculators, for example:

  • OverallRatingCalculator
  • OffensiveRatingCalculator
  • DefensiveRatingCalculator
  • SpecialtyRatingCalculator

Each calculator extends a StatisticCalculator abstract class which has an abstract public function calculate(Player $player) contract. The method takes a single model as the argument and returns a float (for now).

What I'd like to do is have the ability to chain these calculators, and return the entire result as a Collection or some other result object for processing and storage into the database via a separate service.

From the examples I can gather, I've only really seen dumbed down examples of the decorator pattern that returns a simple value, for example a single float/integer. If I wanted to return a more complex data structure that modified itself, what might be the best way to accomplish this?

Should I add another parameter to the calculate() method that will be passed to subsequent calls? If so, what is the best way to generate the initial "empty" result state on the first stop in the decorator chain?

If I'm bastardizing this pattern, I am open to any alternatives.

Thanks in advance!

28 Mar
3 years ago

jakeharris started a new conversation Testing Event Listeners -- Am I Doing This Right?

I'm pretty new to testing, and especially so to mocks. I have a listener which updates an eloquent model when the file is successfully stored in S3. I'm not sure if I'm "supposed" to be mocking the Eloquent model, but my gut says no.

Then again, the listener calls an setHash() method on the model... Should I be mocking the object and do a shouldReceive on that? If so, what would the assertions be, if I'm no longer checking the database?

Am I doing this right?

<?php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class CloudFileTest extends TestCase
{
    protected $cloudFile;

    public function setUp()
    {
        parent::setUp();

        $this->cloudFile = Mockery::mock(\App\DataTransfer\Files\GenericCloudFile::class);

    }
    /**
     * A basic test example.
     *
     * @return void
     */
    public function test_storing_file_hash_updates_models_hash_name()
    {
        $faker = \Faker\Factory::create();

        $md5 = $faker->md5;
        $this->cloudFile->shouldReceive('getHash')->once()->andReturn($md5);

        $ad = factory(\App\Models\Coop\Ad::class)->create();
        $event = new \App\Events\Files\FileWasStored($this->cloudFile, $ad);
        $listener = new \App\Listeners\Files\StoreFileHashReference();

        $listener->handle($event);

        $this->assertSame($ad->getFileHashName(), $md5);
    }

    public function tearDown()
    {
        Mockery::close();
    }
}
03 Sep
3 years ago

jakeharris left a reply on Search: Get Or Post?

I prefer GETs mostly because it's easy to copy and paste those links and/or bookmark them.

Also, it doubles as an interface for any power users--e.g. modifying GET params to update their search quickly.

I try to reserve POSTS for when I'm actually PUTting data into storage on the server, but that's just a personal preference. I have no idea what the "standard" is, but this rule of thumb seems to work for our smaller team.

17 Jul
3 years ago

jakeharris left a reply on Persist Data From A Repository File With A Job Command

Excellent! Glad you got it working!

jakeharris left a reply on Only One Test Will Pass At A Time (5.1)

Thank you so much for responding. I can't remember why I added the __construct(), and I'm certain at some point I was calling the parent-- but eventually took it out in a fit of rage trying to get thing to work. In any case, removing the thing altogether seemed to do the trick.

I'm sure I'll be harassing you in the slack channel again soon enough :)

16 Jul
3 years ago

jakeharris left a reply on Problem With Laravel And Vue

Just a guess since I cant currently test, but try adding a messages: [] array to the data prop on the same level with newMessage

jakeharris left a reply on Persist Data From A Repository File With A Job Command

The handle() method resolves dependencies automatically on the Job. Have you tried resolving it that way?

jakeharris started a new conversation Only One Test Will Pass At A Time (5.1)

I tried to post this a bit ago but I think the original post got lost in the nether thanks to some pasted smart quotes. If this is a double-post I do apologize.

I'm making a point to work on testing early on with a new project, but having a pretty rough time.

If I run either one of the tests below on their own, it will pass. However, when I attempt to run both tests, I am greeted with:

exception 'ErrorException' with message 'Undefined variable: errors’ in <compiled template path>

The views have some basic validation error rendering using this method: {{$errors->first('email')}}

<?php

class AuthTest extends TestCase {

    function __construct()
    {
        parent::setUp();
    }

    protected $baseUrl = "http://portal.dev";

    public function testUserRegistration()
    {
        $this->visit('/register')
             ->type('valid@email.com', 'email')
             ->press('Register')
             ->seePageIs('/login')
             ->see('The supplied email is already in the system. Login?');
    }

    public function testUserLogin()
    {
        $this->visit('/login')
                 ->seePageIs('/login')
                 ->type('valid@email.com', 'email')
                 ->type('goodpass', 'password')
                 ->press('Sign-In')
                 ->seePageIs('/dashboard'));
    }

}

It would appear something is going haywire with middleware and/or sessions, but I'm quite a bit green when it comes to phpunit, let alone testing Laravel.

Any guidance or clues are appreciated. Thanks!

jakeharris started a new conversation Only One Test Will Pass At A Time

I'm making a point to work on testing early on with a new project, but having a pretty rough time.

If I run either one of the tests below on their own, it will pass. However, when I attempt to run both tests, I am greeted with:

exception 'ErrorException' with message 'Undefined variable: errors’ in <compiled template path>

The view has some basic validation error rendering using this method: {{$errors->first(‘email

15 Jul
3 years ago

jakeharris left a reply on Caching User-specific Data

As far as I know, they are. I'm 90% positive--though you're correct they seem to have disappeared from the docs after 4.2...

jakeharris left a reply on (Help) ErrorException In SongsController.php Line 31 Take A Look Here!!!

I'd suggest injecting your Request into the controller methods like so:

    public function store($request Illuminate\Http\Request){

        $input = $request->all();
        
        Song::create($input);

        return redirect('/');
        
    }

I'd also recommend creating a custom request class to handle your validation. See the docs here:

http://laravel.com/docs/master/validation#form-request-validation

14 Jul
3 years ago

jakeharris left a reply on Caching User-specific Data

Not sure if there's a best practice, but here's what I do. I typically use cache tags to categorize my cache items and use whatever unique ID I had available as the key.

When I'm feeling lazy or don't have a need for tagging, I'll just do something like: PROVIDER_NAME.UNIQUE_ID

13 Jul
3 years ago

jakeharris left a reply on Using Auth In Service Provider To Get User Object

Good call on the composer running once for each partial -- I didn't think of that.

A better way might be to inject the Request as a dependency like so:

<?php

namespace Fitness\Providers;

use Illuminate\Http\Request;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot(Request $request)
    {
    view()->share('user', $request->user());
    }
}

Alternatively, I think you can always use Auth::user() or Request::user() in the view itself.

I don't have time to test those, but I will check them if I get a minute or two.

jakeharris left a reply on White Screen

Potentially silly question, but you didn't mention it, so I'll just throw it out there--

Have you "composer installed" from the project root?

Is there anything in storage/logs/laravel.log?

10 Jul
3 years ago

jakeharris left a reply on Using Auth In Service Provider To Get User Object

Yeah, I've never had an issue using Auth facade or the auth() helper method, but since this is the boot() method in the service provider, I think it's just related to the Guard class not being fully initialized in the container's boot() method.

Throwing it into the view()->composer() method may just queue it until Guard is fully booted.

jakeharris left a reply on Using Auth In Service Provider To Get User Object

There's some oddness with the container there and I'm not entirely sure what the deal is, but I've found a view composer will do the trick--if only as a temporary workaround until someone smart can come along and answer the question:

<?php

namespace Fitness\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        view()->composer('*', function() {
            $user = auth()->user();
            dd($user);
        });
    }
}

jakeharris left a reply on Using Auth In Service Provider To Get User Object

Are you attempting to use a view composer? Could you post some code?

09 Jul
3 years ago

jakeharris left a reply on How To Organizers Controllers With Same Set Of Function

You definitely want to throw the duplicate code into a base controller of some sort and have your alpha, beta, gama, etc. controllers extend it. Since you're on laracasts, I'd highly recommend watching this video series which covers the basics of OOP. There's something here for almost any skill level, and I still re-watch it from time to time: https://laracasts.com/series/object-oriented-bootcamp-in-php/episodes/1

02 Jul
3 years ago

jakeharris left a reply on Laravel 5 Php Artisan Migrate Does Not Work

As mentioned above, you might need to configure your .env file. To do this, you can simply copy/rename the .env.example to .env and set the appropriate values there.

jakeharris left a reply on Laravel 5 Php Artisan Migrate Does Not Work

Sounds like your database doesn't exist. Have you created the database in MySQL or created the SQLite file?