Reached

Reached

Lead Frontend Developer at Ulobby

Member Since 5 Years Ago

Aarhus

Experience Points
45,690
Total
Experience

4,310 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
378
Lessons
Completed
Best Reply Awards
20
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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 10
45,690 XP
Aug
30
3 months ago
Activity icon

Replied to Writing A Mock Api For Algolia Testing (ideas And Feedback Needed)

@sti3bas wow, amazing! Will look into it!

Great job!

Aug
20
3 months ago
Activity icon

Replied to How To Show Method With Multiple IDs?

No, make your show endpoint separate from your index for sure.

Something like this: Route::get('/api/members/{member}', '[email protected]');

Activity icon

Replied to Using Laravel Passport For User Authentication

Yes, works wonderfully.

Aug
18
3 months ago
Activity icon

Replied to Can't Get Store Api Call To Work.

Seems like your new issue is related to your config, could you post your database config?

Aug
08
3 months ago
Activity icon

Replied to Adding A Holiday Message

I don't think there is any better way if you want to make sure it's persisted across their whole company.

You could create a flag called back_at and make it a timestamp (instead of the boolean), then you can kind of kill two birds with one stone :).

Check for null (which means = false) or if the timestamp is set (which means = true) on that flag.

Aug
01
4 months ago
Activity icon

Replied to Writing A Mock Api For Algolia Testing (ideas And Feedback Needed)

@audunru thanks for your reply! Using a sandbox is a great idea, although I am not completely sure that Algolia has something like this :/.

Would be great with some kind of API sandbox environment where you could upload a JSON file and mock it this way - perhaps a new side project idea to pursue :)

Jul
22
4 months ago
Activity icon

Replied to Data Isn't Saving Into Db In Laravel

Did you try what I suggested?

Jul
21
4 months ago
Activity icon

Replied to Algorithm

When you create the event just make a loop that runs 5 times, otherwise I am unsure of your question? :)

Activity icon

Replied to How To Make Menu Active In Slidebar Menu

You could pass the active state in as a prop? :)

Activity icon

Replied to Data Isn't Saving Into Db In Laravel

Add the values to the $fillable array on the model, or make an empty guarded array (also on the model) :)

protected $fillable = ['category_name', 'category_description', 'category_slug', 'category_image'];

or

protected $guarded = [];
Jul
17
4 months ago
Activity icon

Commented on Avoid Flags

This video series is probably my favorite in a long time, keep up the good work @jeffreyway ! :)

Activity icon

Started a new Conversation Writing A Mock Api For Algolia Testing (ideas And Feedback Needed)

I am writing a bunch of tests to gain more confidence in my codebase. The tests work fine, but as part of the app there is a call that is made with Scout to Algolia and it returns some geobased results. After searching I haven't found a good way to test this behavior, so I was thinking about mocking up the API results from Algolia and then testing against that instead.

My concern is that potentially this will be very brittle, and I am unsure of whether or not it will actually serve my purpose or not.

Does anyone have any experience doing this or something similar? I am not looking for a solution, just some good ideas/advice I guess, my own solution would be to write a class with some different methods depending on what query parameters are sent with the "request".

Thanks in advance!

Jul
05
5 months ago
Activity icon

Replied to Returning A Single Record Instead Of Collection

It actually works with that package, however I had to do some small changes :)

Step one:

I made a new Class called `ContractUser

<?php

namespace App;

use Illuminate\Database\Eloquent\Relations\Pivot;

class ContractUser extends Pivot
{

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function contract()
    {
        return $this->belongsTo(Contract::class);
    }
}

I then added a new foreign key inside my intermediate pivot table:

public function up()
    {
        Schema::create('contract_user', function (Blueprint $table) {
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('contract_id');
            $table->unsignedBigInteger('campaign_id');

            $table->foreign('user_id')->references('id')->on('users');
            $table->foreign('contract_id')->references('id')->on('contracts');
            $table->foreign('campaign_id')->references('id')->on('campaigns');
        });
    }

And last but not least added a new method to the Campaign model:

public function contractUser() {
        return $this->hasOneDeep(Contract::class, [ContractUser::class])->latest();
}

Then when I want to use it:

return Campaign::with('contractUser')->first();

Heavily inspired by this thread on SO:

https://stackoverflow.com/a/56832439

Activity icon

Replied to Returning A Single Record Instead Of Collection

I just found this package, and it has a method called hasOneDeep, that might work, will try it out and report back:

https://github.com/staudenmeir/eloquent-has-many-deep#hasonedeep

Activity icon

Replied to Returning A Single Record Instead Of Collection

@mstrauss thanks for helping out!

hasOneThrough is definitely interesting, and I also looked at it, but I don't think it will work for my setup, it seems to be looking for a campaign_id foreign key on my user model (which it doesn't have), and that is not really an option since I need the user to be able to have contracts with multiple Campaigns at a time (but never more than one with the same Campaign)

The migration for Contracts:

$table->bigIncrements('id');
$table->unsignedBigInteger('campaign_id')->nullable();
$table->foreign('campaign_id')->references('id')->on('campaigns');
$table->timestamps();
Activity icon

Started a new Conversation Returning A Single Record Instead Of Collection

Hi guys,

I am building an API where I have 3 different models:

Campaign Contract User

A Campaign can have many different Contract, belonging to many different User. A User can only have one Contract with the same Campaign at a time.

I am using a pivot table as an intermediary between Userand Contract.

I basically want to return a single Campaign with the Contract for the currently logged in user, however I think my relationships are setup wrong for this, because I get a collection of Contract belonging to a Campaign, when all I really want is just one Contract.

My current solution is to loop over all of the Contract and return the one that belongs to the User but that seems really inefficient to me..

My Campaign model:

class Campaign {
    public function contracts()
    {
        return $this->hasMany(Contract::class);
    }
}
    

My Contract model:

class Contract {
    public function campaign()
    {
        return $this->belongsTo(Campaign::class);
    }
}

My User model:

class User {
    public function contracts()
    {
        return $this->belongsToMany(Contract::class);
    }
}

I tried the following, but it returns a collection of contracts as mentioned above, not quite what I want. Any ideas here? :)

auth()->loginUsingId(1);
    return $campaign = \App\Campaign::with(['contracts.user' => function($query) {
        return $query->where('user_id', auth()->id());
    }])->find(2);
Jun
17
5 months ago
Activity icon

Replied to Replace Jwt Authentication By Passport

Did you completely uninstall the other package? That's probably whats causing issues, if you follow the documentation then it will work (I did it myself a week ago).

Activity icon

Replied to Login And Registration

If you want to get up and running fast (or you don't necessarily want all of the extras that it bring) then use php artisan make:auth otherwise roll your own. :)

Activity icon

Replied to How To Get New Data With Ajax Post?

When you console.log(response) what is shown to you?

Jun
04
6 months ago
Activity icon

Replied to Ideas For Implementing Customer-levels

@martinbean awesome and simple solution! I was overcomplicating things with intermediary tables and such, thanks for helping out :)!

Activity icon

Replied to Ideas For Implementing Customer-levels

@martinbean so the three levels are gold, platinum and diamond, and it’s basically a representation of the customers current status. Certain campaigns will only be shown to customers with a certain level (e.g. Diamond)

Activity icon

Replied to Ideas For Implementing Customer-levels

@jlrdw thanks for your reply, however my question was not a UI question, but more a database structure question, sorry if that wasn’t clear enough, I will add it to the original question.

Activity icon

Started a new Conversation Ideas For Implementing Customer-levels

Hi guys,

I am about to start a new project where I would like some ideas on the best way to structure things on the database side of things before I start.

Structure:

  1. I have Campaigns that are offers which Customers can "accept/choose"
  2. I have 3 different Levels which a Customer can "have"
  3. Any Campaign can only be accepted/chosen by one Customer

Has anyone got any experience implementing something like this? Any advice would be appreciated!

Best, Casper