yoeriboven

yoeriboven

Member Since 6 Months Ago

Experience Points 16,160
Experience Level 4

3,840 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 157
Lessons
Completed
Best Reply Awards 0
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.

19 Apr
2 months ago

yoeriboven started a new conversation ExpectException() Doesn't Work When It Is Catched

Here's my (simplified) code:

/** @test */
public function it_throws_an_exception()
{
    $this->expectException(PrivateProfileException::class);

    $this->post('/', []);
}

public function store(Request $request) {
    try {
        throw new PrivateProfileException();
    } catch (PrivateProfileException $e) {
        dd('The profile is private');
    }
}

The test fails every time. When I remove the catch block the test succeeds.

I guessed I had to add $this->withoutExceptionHandling() at the top of my test but this doesn't change anything. Even going into the App\Exceptions\Handler and throwing every exception in the render method didn't help at all.

How do I see the exception with the test, but just catch it when accessing through the browser?

03 Apr
2 months ago

yoeriboven left a reply on Comparing Factory To Eloquent Model

@XSECRETS - No, that doesn't work.

Here's my code:

$user = factory('App\User')->create();

$this->actingAs($user);

$settings = factory('App\Settings')->make();

$this->post('settings/details', $details->toArray());

$this->assertTrue($settings->is($user->settings); 

        

The test doesn't pass because the is method return false.

yoeriboven left a reply on Comparing Factory To Eloquent Model

@XSECRETS - Returns false unfortunately.

Maybe because the instance coming from the db contains id, user_id, etc... ?

yoeriboven left a reply on Comparing Factory To Eloquent Model

@SIANGBOON - I'm doing that already.

Just want to access the object through $user->settings to check if it is returning the correct values.

yoeriboven started a new conversation Comparing Factory To Eloquent Model

My app uses a Settings model and every User has a hasOne relationship with a Settings model.

In my tests I create a Settings instance with a factory and then add it to the database through the endpoint. This settings object is then retrievable through $user->settings.

How would I check if everything is saved correctly? I could do this for every property of the Settings modal but that seems a bit redundant:

$this->assertEquals($user->settings->slack_id, $settings->slack_id);

There should be a way to check if all properties are the same. I can't use the code below, because the object coming from the database also contains an id, user_id, created_at and updated_at.

$this->assertEquals($user->settings, $settings);

Any idea how to compare an Eloquent instance to a Factory instance?

22 Mar
3 months ago

yoeriboven left a reply on Mocking Class Doesn't Work

@TALINON - Oh, Wow...

This problem has costed me a full morning.

Thanks for your answer.

I suppose we all sometimes have that moment of: 'wow, how stupid am I' when programming.

Thanks again.

yoeriboven started a new conversation Mocking Class Doesn't Work

Trying to mock class Bar but it doesn't seem to work. Here's my code:

`` // Routes.php Route::get('/', '[email protected]');

// HomeController.php public function index(Foo $foo) { dump($foo->handle()); }

// Foo.php class Foo { protected $bar;

public function __construct(Bar $bar)
{
    $this->bar = $bar;
}

public function handle()
{
    return $this->bar->action('username');
}

}

// Bar.php class Bar { public function action($username) { dump('Called method anyway');

// Do whatever this class needs to do

return 'x';
}

}

`` Trying to mock the action method in the Bar class. It shouldn't hit the method but return what is specified in the mock.

`` $this->mock(Bar::class, function ($mock) { $mock->shouldReceive('action')->andReturn('Mocked value'); });

$this->get('/'); ``

This keeps return 'x' and dumping 'Called method anyway'. Mocking the Foo class and handle method works as expected but for some reason I can't seem to mock Bar.

Any idea why?

14 Mar
3 months ago

yoeriboven left a reply on Axios Works Fine Without Meta CSRF

Yes, even in incognito tabs.

In Laravel Debugbar, under Session I can see the token is set.

Does Axios maybe take the value from the header and send it with the request? In that case, why would you ever set the meta tag?

yoeriboven left a reply on Axios Works Fine Without Meta CSRF

@SNAPEY - Yes it is.

Whether the meta tag is set or not, the token is sent in the xhr request.

yoeriboven left a reply on Axios Works Fine Without Meta CSRF

@jorpedito That is how I generated authentication but I immediately swapped out app.blade.php with my own views so it's not in there anymore.

@snapey I know this is not about GET. I am talking about a POST request.

How on earth is it possible the POST requests work without setting the csrf meta tag?

13 Mar
3 months ago

yoeriboven left a reply on Axios Works Fine Without Meta CSRF

@JORPEDITO - Hi,

I understand that.

In my case I do not set the meta tag but it still works. How is that possible?

yoeriboven started a new conversation Axios Works Fine Without Meta CSRF

Even without setting the CSRF field in a meta tag, Axios requests work just fine.

I tested if CSRF is necessary by building a non-Vue form and it fails when I don't pass the CSRF token.

Why do I not need to set it when using Axios?

yoeriboven left a reply on Inject Authorized User Or Get It From Auth()->user()?

@MITRICH - How would I do that? Wouldn't it whip up a new User instance?

yoeriboven started a new conversation Inject Authorized User Or Get It From Auth()->user()?

In a controller I am calling a repository method to get values. Should I use auth()->user() in the repository method or inject it as a function argument?

What's the recommended approach here?

yoeriboven left a reply on How To Create A Php File Caching Mechanism?

You mean you first run the set method, then comment it out and run the get method?

In that case it is because a new instance is created. Don't (only) store the duration on the object. Also store it in the file or as the filename.

07 Mar
3 months ago

yoeriboven left a reply on Which Relationship Would You Choose?

Thanks so much. It works now.

Kinda weird setRelation() is only mentioned in the API docs.

Two small changes had to be made to your code by the way.

  1. $profiles had to be ordered on the id of the Profile. Without it, you might want to get a profile with the id of 28 but if you only follow 10 profiles (and the collection only holds 10 objects) it would be out of bounds.
  2. setRelations() had to be returned
$profiles = $user->following()->get()->keyBy('id');

$posts = Post::whereIn('profile_id', $profiles->modelKeys())->latest()->take($limit)->get();

$posts->transform(function ($post) use ($profiles) {
    return $post->setRelation('profile', $profiles->get($post->profile_id));
});

return $posts;

Again, thanks. Really helping me out here.

01 Mar
3 months ago

yoeriboven left a reply on Which Relationship Would You Choose?

@MARTINBEAN - No, because in your example you didn't use $profile->posts but Post::whereIn.

But this would still mean I'd have to load the same data twice.

28 Feb
3 months ago

yoeriboven left a reply on Which Relationship Would You Choose?

@MARTINBEAN - There's something I'm struggling with.

Next to the post, I want to show the name of the Profile writing the post.

The way I see this possible: add a Profile relationship to Post so when showing the posts you could do $post->profile->name.

This would mean the same profile data is loaded twice. Once in your code to get the ids and again to load the relationship.

Any idea how I could get the profiles already fetched (in the forUser method) added to every post?

25 Feb
4 months ago

yoeriboven left a reply on Which Relationship Would You Choose?

@MARTINBEAN - Thanks Martin.

Slightly unrelated question: why use a Repository instead of a posts() function on User like @mushood does?

22 Feb
4 months ago

yoeriboven left a reply on Which Relationship Would You Choose?

@MARTINBEAN - A user follows profiles. Profiles are like pages with posts attached to them. A user follows a profile and sees the posts of the Profiles they follow in a feed/timeline.

yoeriboven left a reply on Which Relationship Would You Choose?

I was afraid the word Profile would be confusing. A Profile would be someone you can follow. Like a YouTube channel you can subscribe to.

A user can subscribe to many channels. A channel can have many subscribers.

So many-to-many would be the correct relationship.

In that case, option 1 or 2?

21 Feb
4 months ago

yoeriboven started a new conversation Which Relationship Do You Choose?

My app functions kind of like Twitter. A User would follow Profiles which have Posts. A user doesn't have posts, profiles do.

The User and the Profiles are in a Many to Many relationship (so with a pivot table).

I want to show a timeline with all posts uploaded by the profiles which are followed by the logged in user.

There's two ways this could be done:

  1. Setup a Has Many between Profiles and Posts: $user->profiles->posts
  2. Setup a Many To Many between Posts and Users: $user->posts

The second means there will be one query less (profiles won't be fetched) but it also means another pivot table will have to be added. The first option also feels a lot cleaner.

Which option would you choose?