PWParsons

PWParsons

Member Since 1 Year Ago

Experience Points
42,370
Total
Experience

2,630 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
386
Lessons
Completed
Best Reply Awards
3
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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 9
42,370 XP
May
26
2 days ago
Activity icon

Replied to How To Test A View Composer

The following works right...

/** @test */
    public function it_passes_the_parent_categories_to_the_view(): void
    {
        $composer = new CategoryComposer;
        $view = $this->spy(View::class);

        $composer->compose($view);

        $view->shouldHaveReceived('with')->once();
    }

it fails when checking if the correct data is passed to the view...

$view->shouldHaveReceived('with')
            ->with('categories', Category::getParents())
            ->once();

the error:

Mockery\Exception\InvalidCountException : Method with(<Any Arguments>) from Mockery_2_Illuminate_View_View should be called at least 1 times but called 0 times.

May
25
3 days ago
Activity icon

Replied to How To Test A View Composer

Hey @drewdan , thanks for your reply.

I originally had the parameter as a string and it didn't work. I just changed it to a string because to remove the Expected parameters of type array|array[]warning in PHPStorm.

May
23
5 days ago
Activity icon

Started a new Conversation How To Test A View Composer

I'm new to testing so please forgive me if I am missing something obvious.

I'm trying to test the following view composer:

namespace App\Http\View\Composers;

use App\Models\Category;
use Illuminate\View\View;

class CategoryComposer
{
    public function compose(View $view)
    {
        $view->with(
            'categories',
            Category::getParents()
        );
    }
}

The test:

class CategoryComposerTest extends TestCase
{
    /** @test **/
    public function it_passes_the_parent_categories_to_the_view(): void
    {
        $composer = new CategoryComposer;

        $view = $this->mock(View::class);

        $view->shouldReceive(['with'])
            ->with([
                'categories',
                Category::getParents()
            ])
            ->once();

        $composer->compose($view);
    }
}

The following error occurs when running the test:

Mockery\Exception\BadMethodCallException : Received Mockery_2_Illuminate_View_View::with(), but no expectations were specified

What am I doing wrong?

Dec
07
5 months ago
Activity icon

Replied to Assign Middleware To Only Api Group

Apologies, I misunderstood your question. I thought you were trying to apply the middleware to a group within the api routes.

The route group in my previous answer will return null because it was only an example.

What you are doing in your Kernel is correct. Maybe something else is wrong?

I tested the following in Laravel 6.6.2 and it works fine:

protected $middlewareGroups = [
    'api' => [
        'throttle:60,1',
        'bindings',
        'cors',
    ],
];

protected $routeMiddleware = [
    'cors' => \Barryvdh\Cors\HandleCors::class,
];
Dec
06
5 months ago
Activity icon

Replied to Assign Middleware To Only Api Group

Hi @trogne,

Can you try this in Kernel.php...

protected $routeMiddleware = [
     //...
     'cors' => Cors::class
];

and in your api routes...

Route::group(function () {
    //...
})->middleware('cors');