JorickL

JorickL

Member Since 1 Year Ago

Experience Points 1,170
Experience Level 1

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

07 Mar
1 month ago

JorickL left a reply on Swap Class When Running Test?

@TALINON - Thank you, very much! I've got it working now. Only, I had this line:

$this->app->bind(TicketInterface::class, TicketAPI::class);

placed in my AppServiceProvider::register() method. WRONG! When testing and dd() the bookings() method on both of my Classes, it keep going to the TicketAPI::class, where I wanted the FakeTicket::class to be called. Then, I remembered something about the method priorities in a ServiceProvider and thought: well, maybe I should put it in the boot() method of my AppServiceProvider...

BINGO It worked! Thanks a lot, Talinon!

06 Mar
1 month ago

JorickL left a reply on Swap Class When Running Test?

@TALINON - Yes, thanks! What I said, I tried before the way I described earlier, but not like you suggested. I will try your way tomorrow morning and will come back to you to let you know if it worked (and mark your answer as best...).

JorickL left a reply on Swap Class When Running Test?

@TALINON - Yikes! Didn't saw your edit: that's... Brilliant. I tried similar, but without the resolve() in my model. Will try that again... I'll let you know!

Thanks in advance!

JorickL left a reply on Swap Class When Running Test?

@TALINON - Thanks! I'll will try this! About the interfaces: both classes (TicketAPI and FakeTicket) implement a TicketGatewayInterface. That holds two functions:

<?PHP

namespace App\Tickets;

interface TicketGatewayInterface 
{
    public function bookings();

    public function notes();
}

When I tried to use the interface like this:

$connection = (new TicketGatewayInterface)->bookings($attributes);

It shouted something like "can't instantiate interface" etc. I tried putting it in the models constructor (which before that didn't exist) and then it threw an error that the constructor attributes expected 2 arguments and only one was given.

Then I lost it and reversed everything back from where I started and asked Laracast for a bright light! ;-)

JorickL started a new conversation Swap Class When Running Test?

In my Laravel 5.7 I want to 'fake' an API endpoint of a service we use. I've created a 'Fake class' which acts as the API. In my models I whip up a new connection to the external API like this:

$connection = (new TicketAPI)->bookings($attributes);

This works, like a charm.

Now, I want to replace, or 'swap' the TicketAPI::class when I'm running tests. So, I thought I could use

$fakeTicket = new FakeTicket;
$this->app->instance(TicketAPI::class, $fakeTicket);

But it still reaches the TicketAPI::class. Is someone able to point me in the right direction, or am I trying to use the $this->app->instance() method in the complete wrong way? Is it even possible to swap classes like this?

04 Mar
1 month ago

JorickL left a reply on How To Export Database Table To Excel File In Laravel

@konrms Glad to see you've fixed it! Happy exporting! ?

JorickL left a reply on How To Export Database Table To Excel File In Laravel

Well, first of all, you're not returning anything in UsersController export() method. Try to find out the source. What happens if you dd(new UsersExport); in your export method? Does it initiate a new UsersExport class? And what happens if you dd((new UsersExport)->collection);? Does it return an Eloquent Collection with all users? And if nothing is working, just die('Export Method on UsersController called'); on the export method to literally see the methods fail...

Apparantly, the missing 'method="GET"' on your form is OK, because it reaches the UsersController, I suppose?

For what I can see now, it should work OK...

03 Mar
1 month ago

JorickL left a reply on How To Export Database Table To Excel File In Laravel

Please be consistent with lower- andere uppercase. Classnames should be CamelCase and thus have a Capital letter at the beginning. Fix that, make sure you've imported the (right) classes en try again.

01 Mar
1 month ago

JorickL left a reply on How To Export Database Table To Excel File In Laravel

It looks like that your <form> doesn't provide the correct method to reach the controller. First of all, it looks like a simple GET request to me and it would be a normal link; no form required.

What happens when you type in the URL directly into the addresbar of your browser?

12 Oct
6 months ago

JorickL left a reply on Organize Polymorphic BelongsTo Save

@D9705996 Alright! I've figured it out. Because I already have a polymorphic relation between each Locomotive::class, Carriage::class etc. to my MaintenanceOrder::class and did a bit of searching on Google, I found out about Explicit Model Binding.

In my RouteServiceProvider::boot method I declared every possible 'unit type', and in my routes/web.php I did it as well. Therefore I'm able to fetch the complete model in the MaintenanceOrder::create($unit) method.

It looks like this:

RouteServiceProvider.php

public function boot() {
    parent::boot();
    Route::model('locomotive', \App\Locomotive::class);
    [...]
}
routes\web.php

[...]

Route::get('maintenance/order/locomotive/{locomotive}', '[email protected]');

[...]
10 Oct
6 months ago

JorickL left a reply on Organize Polymorphic BelongsTo Save

Holy, thanks for your time! And the great answer! I'm going to read it all again once more and I think I've found the right solution. Especially about the hint for extracting to a base class. As long as I'm able to work with one 'base model' like Locomotive, I'm able to rerun back to the maintenanceorders, one way or another.

I'll let you know what the results are! Thanks - a lot! Fresh eyes on this piece of magic is much appreciated!

JorickL left a reply on Organize Polymorphic BelongsTo Save

@D9705996 Hi! Yes, it can have (and certainly will) have multiple orders.

  1. Is more complicated. It is about rolling stock. You have locomotive, carriages and multiple units as models that will require maintenance. Every model of that particular type, hasMany units. Units share the same table, as the information there is the same across all the units. So there is already a polymorphic relation between unit types and individual units.

As the maintenance orders are based on a type and not on a singular unit, but all the maintenance shares the same base, but on a lower level is split up into several maintenance tasks and so on.

Because of the unit types share the same maintenance order class, but are completely different as types itself, the only way of letting these talk 'together' in my imagination was to use polymorphism.

Is it clear, or should I describe in more depth? Thanks for your help and interest anyway!

JorickL left a reply on Organize Polymorphic BelongsTo Save

Allright! So, I've to figure out how that thing will work then.

JorickL started a new conversation Organize Polymorphic BelongsTo Save

OK, here's the deal. I have a situation were there are 3 models, which can have one relation to another model. Let's say we have 3 producttypes and every producttype has a maintenance order.

What is the best way to attach a new maintenance order to one of the producttype models? At first the most 'easy' solution that I could've think of is to create one MaintenanceOrderController which hold the 'create' method. But... How is that controller going to find out to which related model it belongs, if I can only give an ID?

So my table of maintenance_orders looks like this:

id producttype_id producttype_type
1  1                              App\Wasmachines
2 1                             App\Computers
etc...

Any good advice how to fix this, without having the need to create 3 methods in every prodducttype controller to be able to save those maintenanceOrders?

24 May
10 months ago

JorickL left a reply on Getting All Objects If The Latest Status Is E.g. '100'

Probably you have to put ->get() before last() because the last() method is a collection method and not a query builder method.

$query->where('status', 100)->get()->last();

JorickL left a reply on Getting All Objects If The Latest Status Is E.g. '100'

$passes = Pass::select([
            'id',
            'type',
        ])->whereHas('processes', function ($query){
            $query->where('status', 100)->last();
        })->get();

Wouldn't it be just this easy?

23 May
10 months ago

JorickL left a reply on Using Registered() Method In Illuminate\Foundation\Auth\RegistersUsers

@alexpgates Yes, that's exactly what you must do. As @Snapey said, you shouldn't make any changes in the vendor folder.

The \Auth\RegisterController.php uses the RegistersUsers trait from Illuminate\Foundation\Auth\RegistersUsers.php and thus will call all the methods in there and in your RegisterController.php.

In your routes\web.php you'll also point at that controller for registering a user.

JorickL left a reply on Using Registered() Method In Illuminate\Foundation\Auth\RegistersUsers

In App\Http\Controllers\Auth\RegisterController.php you can just override the default registered() method by creating it in the Registercontroller.php

02 Feb
1 year ago

JorickL left a reply on Handle Multiple Unknown Relations

Thinking days about how to solve this issue... And while I'm sending this question to the forums, I came up with a solution myself, I think... Will try the following and keep ya'll updated:

Create a Setting Model (with corresponding migration file) and create the following table structure:

id - integer
setable_id - unsignedInteger
setable_type - string
key - string
value - string
softDeletes()
timetamps()

Then, every model you want to store specific settings, use the key as the 'group' for settings, value for it's result.

public function Settings()
{
    return $this->morphMany(\App\Settings::class, 'setable');
}

This will do the job, I guess...

JorickL started a new conversation Handle Multiple Unknown Relations

OK, so here's the deal... I'm building a webapp with Laravel 5.5 and so far I'm running OK. Just some default relations, including polymorphic. But I'm uncertain how to handle the following.

I have a App\RollingStock model and that has a (one) Type() Polymorphic relation. The deal is, I want to track certain measurements. Think about if the machine has already had a daily checkup, how much diesel is still in the tanks, et cetera.

I was planning on using one column on my rolling_stocks table, which held 'certain' attributes as a comma-separated list or something, but then... How to handle this data? And by that, not every Rolling Stock has diesel (there are electrical locomotives as well, but they will need a daily checkup, for example).

Is there someone around here who has a genius solution?