__gregory

Member Since 7 Years Ago

Zurich

Experience Points
12,240
Total
Experience

2,760 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
120
Lessons
Completed
Best Reply Awards
1
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.

  • Community Pillar

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

Level 3
12,240 XP
Feb
23
1 week ago
Activity icon

Replied to Difference Between ActingAs($user) And Auth::login($user)?

$this->actingAs() is just setting the user to current guard. Auth::login() is updating the session, remembering the user by setting the token and cookie, and it is firing the events and setting the user to the guard.

Ok this makes sense now, because I have a Listener that adds data to the session when a user logs in. I have now changed a line in my test to this and it passes:

$response = $this->actingAs($user)
    ->withSession(['tenant_id' => $tenant2->id])
    ->get(route('reports.show', $report));

Also, you should not assert that the resource is not found, you should assert that it is forbidden to access that resource.

Could you please elaborate on this? I am using Laravels route model binding feature and what basically happens is that Laravel is throwing a ModelNotFoundException and rendering a view with a 404 status code. I don't have a lot of experience in writing tests so I am wondering what would be a better approach to test this kind of stuff?

Thanks!

Activity icon

Started a new Conversation Difference Between ActingAs($user) And Auth::login($user)?

Hello,

I'm wondering what's the difference between $this->actingAs($user) and Auth::login($user) in tests.

I want to test if Laravel shows a 404 page if a user is not allowed to see a resource. When I use Auth::login($user) it works:

    /**
     * @test
     */
    public function show_displays_404()
    {
        $tenant = Tenant::factory()->create();
        $tenant2 = Tenant::factory()->create();

        $report = Report::factory()->create(['tenant_id' => $tenant->id]);
        $user = User::factory()->create(['tenant_id' => $tenant2->id]);

        Auth::login($user);

        $response = $this->get(route('reports.show', $report));

        $response->assertNotFound();
    }

But when I use $this->actingAs($user) the test fails ("Response status code [200] is not a not found status code."), meaning the user can see the ressource he's no allowed to:

    /**
     * @test
     */
    public function show_displays_404()
    {
        $tenant = Tenant::factory()->create();
        $tenant2 = Tenant::factory()->create();

        $report = Report::factory()->create(['tenant_id' => $tenant->id]);
        $user = User::factory()->create(['tenant_id' => $tenant2->id]);

        $response = $this->actingAs($user)->get(route('reports.show', $report));

        $response->assertNotFound();
    }

So what's exactly the difference here? I expected $this->actingAs($user) to be working the same way as Auth::login($user).

Thanks!

Dec
11
2 months ago
Activity icon

Replied to Is Laravel The Right Choice For A Small Webshop?

Have a look at OctoberCMS and the Mall plugin (https://github.com/OFFLINE-GmbH/oc-mall-plugin). It makes it very easy to create a shop and it‘s built on Laravel. Building a shop from scratch is a lot of work, so be careful what you choose :)