falnyr

falnyr

Backend/DevOps engineer at Auckland

Auckland

Member Since 2 Years Ago

Experience Points 9,120
Experience
Level
Lessons Completed 88
Lessons
Completed
Best Reply Awards 0
Best Answer
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.

14 Feb
9 months ago

falnyr started a new conversation Lazy Loading Attributes

Hi, I have an attribute method getFooAttribute which performs quite a complicated algorithm.

The models resource object contains this attribute but I'd like to have a condition for it (only for show method, not index)

With relationships I am using whenLoaded, is there something similar I can use for this case?

20 Dec
10 months ago

falnyr left a reply on Enforcing Strict Types In Php 7

Wrong, wrong, wrong.

Declaration of strict_types needs to be present in every file that wants to be managed as strict. If you would be able to set that globally, there is no certainty that third-party libraries that you use are prepared for strict types.

28 Nov
11 months ago

falnyr left a reply on Updating Model With Relationships In A Single Request

Could you please reference the whole method? Even setting only the properties that were passed in the form.

27 Nov
11 months ago

falnyr started a new conversation Updating Model With Relationships In A Single Request

Hey there, I have a Post and Tag entities. Post can have many Tags and I want to update them in a single method like:

post.name = 'Foo' post.random = 'Alpha' tag[1][id] = 1 tag[1][name] = 'Bar' tag[2][id] = 2 tag[2][name] = 'Baz'

public function update(Request $request, Post $post)
{
    $post->update([
        'name' => $request->get('name'),
        'excerpt' => $request->get('excerpt'),
    ]);

    if ($tags = $request->get('tags')) {
        foreach ($tags as $tag) {
            $tagObject = Tag::where('id', $tag['id'])
                ->where('post_id', $post->id)
                ->firstOrFail();
            $tagObject->update($tag);
        }
    }

    return $post;
}

Now this ofc. removes the excerpt (since no value was provided) and saving the tags feels a little weird - there must be a better way.

Do you know how to save only fields that were provided in request, discard the non-existing (random) and save relationships efficiently?

15 Nov
11 months ago

falnyr started a new conversation Validation In API

Hey there, I am trying to use validation method in my controller:

$validation = $this->validate($request, ['title' => 'required']);

Instead of getting errors or exception I am redirected to /, since Exception handler is providing validation errors to be displayed in HTML. (For this case I also registered my own exception handler, but it doesn't feel right)

Is there something like Laravel "API mode" which adds validation errors to the response and manages exceptions or do I need to take care of that part?

14 Nov
1 year ago

falnyr started a new conversation Testing API With Bearer Token

Hey, I am trying to test several endpoints in my API. Authentication is provided via laravel/passport's Password Grant Token.

What I have right now is a TestCase class with this:

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

        $clientRepository = new ClientRepository();
        $this->client = $clientRepository->createPasswordGrantClient(
            null, 'Test Personal Access Client', ''
        );

        $this->user = create(User::class, [
            'password' => bcrypt('secret')
        ]);

        $response = parent::postJson('/oauth/token', [
            'client_secret' => $this->client->secret,
            'client_id' => $this->client->id,
            'grant_type' => 'password',
            'username' => $this->user->email,
            'password' => 'secret',
        ]);

        $this->token = $response->json()['access_token'];

        Auth::login($this->user);
    }

This works without a problem, the only thing is it takes a lot of performance, 20 tests take about 10 seconds to execute since this is happening for every test.

I was thinking of creating a helper class and using PHPUnit's static method setUpBeforeClass, but if I do that, $clientRepository is missing context and everything fails.

Any ideas?