Reached

Reached

Member Since 5 Years Ago

Aarhus

Lead Frontend Developer at Ulobby

Experience Points 45,550
Experience Level 10

4,450 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.

08 Aug
1 week ago

Reached left a reply on 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.

01 Aug
2 weeks ago

Reached left a reply on 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 :)

22 Jul
3 weeks ago

Reached left a reply on Data Isn't Saving Into Db In Laravel

Did you try what I suggested?

21 Jul
3 weeks ago

Reached left a reply on Algorithm

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

Reached left a reply on How To Make Menu Active In Slidebar Menu

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

Reached left a reply on 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 = [];
17 Jul
1 month ago

Reached commented on Avoid Flags

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

Reached 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!

05 Jul
1 month ago

Reached left a reply on 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

Reached left a reply on 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

Reached left a reply on 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();

Reached 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);
17 Jun
2 months ago

Reached left a reply on 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).

Reached left a reply on 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. :)

Reached left a reply on How To Get New Data With Ajax Post?

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

04 Jun
2 months ago

Reached left a reply on Ideas For Implementing Customer-levels

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

Reached left a reply on 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)

Reached left a reply on 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.

Reached 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

09 May
3 months ago

Reached left a reply on Passing Data Object From Blade To Modal In Laravel

I would use an event bus for this (unless you want to pull in something like Vuex): https://alligator.io/vuejs/global-event-bus/

22 Apr
3 months ago

Reached left a reply on Keyboard Shortcuts For Laravel App

Keyboard shortcuts are handled entirely on the frontend, so there is nothing Laravel specific needed I believe :)

24 Feb
5 months ago

Reached left a reply on Ziggy Trough Webpack

Hi there,

Why don't you want the routes in the HTML ? That is kinda the whole point with Ziggy :) - if you want to hide some routes you can blacklist them in the config!

04 Feb
6 months ago

Reached left a reply on Helping Developers Community

Good job, I like the layout and style :)!

30 Jan
6 months ago

Reached left a reply on Uncaught DOMException: Failed To Execute 'querySelector'

Show us more code, the error is not referenced in your posted code :)

28 Jan
6 months ago

Reached left a reply on How To Design Sample Psd With Bootstrap 4

Looks like you didn't include your image in the html code, otherwise, it should be very simple:

You have a wrapper container which contains your contact-info content and your image, then you just make the wrapper container a flex container, if you add the rest of your markup (with the image) I can show you how.

Reached left a reply on Pignose Calendar Problem

Could you show us some code please?

27 Jan
6 months ago

Reached left a reply on Laravel Does Not Find File Manager After Move To Webserver

You probably need a symbolic link between your storage folder and your public folder:

https://laravel.com/docs/5.7/structure#the-storage-directory

Reached left a reply on Nova Defaults To /home After Changes

/home is usually the default that is set for all authentication within Laravel, try to visit e.g. LoginController.php, there you will see that the $redirectTo property is set to "/home", you could try to change it to "/nova" instead.

Please be aware that this is true for a couple of the other auth controllers that come out of the box with a new Laravel installation

20 Jan
6 months ago

Reached left a reply on How Do I Add Theme Template Css And Js In The Laravel And Vue ?

Did you add your javascript also? :)

Reached left a reply on How To Auth My Laravel API For My IOS App

Yea, definitely use passport for this, it's the easiest i've worked with of the available solutions :)

Reached left a reply on How To Apply The Translation In The .js Script

You can use the package described in this article, we use a similar approach at my job, and it works well!

https://laravel-news.com/laravel-translations-loader

19 Jan
6 months ago

Reached left a reply on Code Review: Is This Okay, Or Should I Be Doing Something...

I think it looks alright! You could always refactor some of the parts into further methods if you think they could be reused :)

Reached left a reply on Echo + Pusher + Vue - Listening For Event Does Not Work

Are you able to see the comments coming from pusher in the developer console (inside your browser)?

Reached left a reply on Is There Any Easy Methods To Using Ajax With Laravel?

To format your code, use Github-flavored code-blocks: https://help.github.com/articles/creating-and-highlighting-code-blocks/ - its just done with 3 backticks (check the link)

What is this tag you are talking about, is that a custom element you created?

Otherwise, you use the outermost element (in my example the body) to be the container for the rest of your elements (also the dynamic ones), then you attach a click handler to the body, and you then use "#your-slug-selector" as the clicked element. In your AJAX success response you then append/prepend the element to the DOM, if you are still in doubt, please attach some code :)

Reached left a reply on Code Review: Is This Okay, Or Should I Be Doing Something...

This is probably mostly a personal preference, but whenever I have logic like this in a controller method, I like to extract it out to a method on my model, so in your case the Attachment model.

You could then give it a nice and readable name that describes what the method does, this way it makes it much easier to scan the controller for future you (or others).

Hope it helps!

Reached left a reply on Echo + Pusher + Vue - Listening For Event Does Not Work

Where in the Comments component are you using the Echo.private function? :) Also, you checked that the Comments component is indeed rendered on the screen right?

Reached left a reply on Doubt Regarding Stripe Package

Hi there,

You could extract it to its own class, and then pull in that class whenever you need it.

Then in the constructor of that class, you pull in the API keys. and set it up.

Hope it helps!

Reached left a reply on Is There Any Easy Methods To Using Ajax With Laravel?

@THEWOODCUTTER - You probably have to do this to make it update since the element is dynamically inserted:

$('body').on("click", "#your-slug-selector", function() {});

You can ready more about it here: https://stackoverflow.com/questions/8752321/jquery-live-vs-on-method-for-adding-a-click-event-after-loading-dynamic-ht

Let me know if it doesn't make sense to you.

Reached left a reply on Include Components By Condition

I would use lazy loading of your components, this way Vue will only fetch what is needed, an example:

const MultiLevelDonutChart = () => import('./Charts/MultiLevelDonutChart.vue');

Then import it in the main component where you want to use it:

export default {
    components: {
        'multi-level-donut-chart': MultiLevelDonutChart
    }
    ...
}

You might have to use babel-dynamic-import to make this work though :)

Reached left a reply on MIX Cache Bursting Vs. Asset URL Directive In Config

Can't you just pull out the value from the asset_url helper and put it in front of the mix path? :)

mix(config('app.asset_url') . '/css/app.css')

Reached left a reply on Vuejs Server Side Rendering

Maybe you could look into using this package? https://github.com/spatie/laravel-server-side-rendering

28 Dec
7 months ago

Reached left a reply on More Verbose PHPUnit Tests With Laravel

Add the withoutExceptionHandling() method :)

public function test_a_workout_can_be_created()
    {
        $this->withoutExceptionHandling();

      ....
27 Dec
7 months ago

Reached left a reply on Different Access

@DOUGLASAKULA - Good to hear :)

Reached left a reply on Sorry, Your Session Has Expired. Please Refresh And Try Again. 5.7

What's your environment like? Windows? Mac with Valet?

Reached left a reply on Different Access

I would write a middleware to handle this on the route level, then if you need to distinguish inside your blade templates it's also really easy to do.

Something like this for your middleware should work:

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class Admin
{
    public function handle($request, Closure $next)
    {
        // "is_admin" should correspond to a column in your user table
        if (Auth::check() && Auth::user()->is_admin) {
            return $next($request);
        }

        return redirect('home'); // Change this to whereever you want to redirect
    }
}
03 Nov
9 months ago

Reached left a reply on Get Sum Of Multiple Item To Array In One Call

Use sum as you do, and then use the callback to do calculations https://laravel.com/docs/5.7/collections#method-sum

Reached left a reply on Set Value To A Form Data

Can you show some more code please?

15 Aug
1 year ago

Reached left a reply on Connect Laravel With Third-party API That Requires A API-key

Store the API key in your .env file, then you can just refer directly to the key where you call the API :)

Then you could make a thin wrapper around the API where you include the key in the constructor.