rikw

rikw

Member Since 3 Years Ago

Experience Points 1,490
Experience Level 1

3,510 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 6
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.

29 Dec
1 year ago

rikw left a reply on Do You Test All Validations For Create And Update Actions?

Thank you @tykus, this is the confirmation I was looking for. I did more or less the same.

28 Dec
1 year ago

rikw started a new conversation Do You Test All Validations For Create And Update Actions?

Hi!

I'm writing tests for my new application and start to wonder... Do you test all form field validations for create and update actions seperately? To me it looks like a lot of test code. Does that make sense?

Cheers! Rik

06 Dec
1 year ago

rikw started a new conversation Object Oriented Components

Hi all,

I'm relatively new to Vue and have mainly worked my way through examples. Now I'm stuck in my next challange. I'm looking for a way to create a base component for a grid/table interface. For all different grids I have a want use the base component and override parts where needed. Or, for instance, set the api url for that implementation. Where do I start?

My reference is how I would do it with php classes... hence my term 'object oriented'.

Thanks!

05 Dec
1 year ago

rikw started a new conversation Convert Collection Into Formatted Array (refactor)

Hi all,

I need to convert a collection into a formatted array so I can return it as json for a javascript component. I have the working code below but I feel this can be done better. Who can point me in the right direction? Thanks for thinking along!

    public function index()
    {
        $users = User::select('status')->distinct('status')->get()->pluck('status');
        $array = [];

        foreach ($users as $user) {
            $array[] = [
                'name' => $user,
                'value' => $user,
            ];
        }

        return [
            'success' => true,
            'results' => $array,
        ];
    }
10 Nov
1 year ago

rikw left a reply on Working With Many-to-many Relations - Filters And Roles

Thx @rumm.am this helped me out. Now I filter on multiple role_codes and find I get users double. I added a distict() to fix this.

rikw left a reply on Working With Many-to-many Relations - Filters And Roles

Hi @rumm.am thanks for thinking with me! I'll try it this evening. For a specific user I would add his ID to there where as well?

09 Nov
1 year ago

rikw started a new conversation Working With Many-to-many Relations - Filters And Roles

Hi all,

I'm working on a project based on a legacy database structure. This turns out to be easier than I expected so I'm happy with that. Now I run into design/architectual issue/question with the m2m relationships. Let me explain....

I have users that can have multiple roles in multiple organizations. For this I have four tables:

  • users
  • organizations
  • users_organizations - user_id, organization_id, role_code
  • roles - role_id, role_code, role_name

With a hasManyThrough I relate the users to the organization through the users_organizations table. Because the entities are related through other fields than the primary key I need to configure those too. This works fine.

    public function users()
    {
        return $this->hasManyThrough(
            'App\User',
            'App\UsersOrganization',
            'organization_cmpwwn',
            'cmp_wwn',
            'cmp_wwn',
            'user_cmpwwn'
        )->select(['role_code'])->where('role_code', '=', 'ContactOrg');
    }

Questions

My current hasManyThrough filters the users so I only get users with a role code of 'ContactOrg'. This is not flexible of course. What is the advised way to proceed?

At some points in my code I want to know if a user has a specific role in a specific organization. This is the reverse of the shown hasManyThrough. What is the trick to get this info? Maybe I can distill this from the answer to my previous question.

How would I incorporate the roles table so I can show role names in my application?

Thank you in advance for thinking with me.

Cheers! Rik

05 Sep
1 year ago

rikw started a new conversation Type Based Tasks

Hi!

I need some advice on structuring some code we are working on. Let me try to explain. We have a list of websites that can be of different types (or cms systems). We want to create a system that can perform remote tasks on those systems through ssh or api. The tasks are the same (add a user) but the execution is different by type.

How can we best create a structure that handles this? Task classes that do a switch on type, polymorph or something different?

Also, can we best add the types as constant to the website model of as a o2m relation to a type model?

I'm looking forward to your thoughts.

Cheers, Rik

09 Aug
1 year ago

rikw started a new conversation Creating Complex Layouts

Hi all,

In my quest for dry templates and code I'm looking for some assistance. My application has different sections from the main menu. Within these sections I'm thinking of either submenu of tabs in the main screen. Of course, I'd like to show the active items in menu/submenu and tabs.

How would I go and approach this? Create separate blade includes for the different menus and tab lists? Is there a way to give the current and active (where subpage is current) states to such templates?

Thanks for your thoughts!

rikw left a reply on Code Structure Behind Controller

@goatshark In my perception repositories are in the middle of data/models and the application to provide flexibility in the future.

@d3xt3r Thanks for your straight forward approach. This is non reusable code and only serves this function. Utility might be a good one too. I think this is the same as Helpers (I'm from the Magento world).

rikw started a new conversation Code Structure Behind Controller

Hi all,

Please assist me with some guidance on structuring my code behind controllers. I try to only use resource controllers. This works well and makes for a clear structure. Now the controllers of course need to collect data and dispatch actions. But how do I structure this?

Example... We need data from an external API (Toggl). This is data about work logs on projects. This data needs to be transformed to fit our needs for a .csv file to import into another tool.

I created a ToggleApiService class to connect to Toggl and call certain endpoints and collect data. My controller now transforms the data to output a csv. This gives quite some code. What would be a good naming scheme/logic to seperate the tranformation from the controller?

Of course this is an example use case. Basically, how do you keep controllers as short as possible and put the logic somewhere else, which aren't models.

Thanks for your thoughts!

13 Jun
1 year ago

rikw left a reply on Writing Tests For SSH

Nobody here that can help me out (just a little bump)?

09 Jun
1 year ago

rikw started a new conversation Writing Tests For SSH

Hi all,

I'm trying to write an application that can perform some remote actions through SSH. The Laravel Collective Remote/SSH package works just fine. Now I'm also trying to write proper tests but have no clue how to approach this for SSH. Who can give a pointer?

08 Jun
1 year ago

rikw left a reply on How To Work With Fixed State/status/type Fields

Hi @neilherbertuk the enum does limit the values in database but doesn't provide a way to select those options right? These need to be hardcoded somewhere.

From the docs I read: The following column types can not be "changed": char, double, enum, mediumInteger, timestamp, tinyInteger, ipAddress, json, jsonb, macAddress, mediumIncrements, morphs, nullableMorphs, nullableTimestamps, softDeletes, timeTz, timestampTz, timestamps, timestampsTz, unsignedMediumInteger, unsignedTinyInteger, uuid.

Does this mean I cannot add values to the enum?

Thank @Screenbeetle for your explanation. I think this will work. This allows future new types/statuses and a way to select them in templates. As for my cron functions I can select the right records based on hardcoded types in code, that link to new records in the type/status table.

07 Jun
1 year ago

rikw left a reply on How To Work With Fixed State/status/type Fields

Thanks for the feedback. Hardcoding isn't preferred but isn't it the only way of knowing for sure in code? I saw the enumerated thing. That limits the values in database. But I need to be able to add values and use them in templates. Would it make sense to use a table with id, code and name fields? Code being a unique that I use in the code. This I can fill with a seeder.

rikw started a new conversation How To Work With Fixed State/status/type Fields

Hi,

I want my records to have a status or type which I can act on. So basically open/closed or typeA/typeB/typeC. I want need to select records of a known type to do some repeating action. It doesn't seem right to use a o2m relation as it works on database id's, not so handy for code. What is better way to approach this in a Laravel way?

Cheers!

02 Aug
2 years ago

rikw left a reply on Date Field Shown As -0001-11-30 00:00:00

Hi @selmonal, I had that. But submittting an empty field makes it store 0000-00-00 00:00:00 in stead of null. Is that to be expected?

The situation occures when I create a new record with only one field filled. Then the edit screen shows empty date fields. When I submit those fields things go wrong.

01 Aug
2 years ago

rikw started a new conversation Date Field Shown As -0001-11-30 00:00:00

Hi,

I have a model and form which I cannot get right. My database fields are of type date and datetime. Both fields are added to the dates array. When I save the form with empty values the database stores as 0000-00-00 00:00:00. But the edit form then shows -0001-11-30 00:00:00. I just cannot get it right. Who can help me?

Cheers! Rik

08 Jun
2 years ago

rikw left a reply on Seperate Logins On Same Email Address

Sweet @martinbean, I can really work with this. Thanks for thinking with me and showing me a good solution.

07 Jun
2 years ago

rikw left a reply on Seperate Logins On Same Email Address

Hi @martinbean and @Kemito that helps a lot. With both I think I can manage my challenge. Maybe not the easiest one while starting Laravel.

Maybe one last tip I could use. At what point should I find the current (sub)domain? The whitelabels use their own domain the they 'send' to our platform. Like: sub1.domain-a.tld, sub2.domain-b.tld.

These kind of questions might show I'm struggling a bit with this structure in Laravel.

rikw left a reply on Seperate Logins On Same Email Address

Thanks @martinbean that sounds like a plan. That would mean a custom Guard for login/authentication am I right?

rikw left a reply on Seperate Logins On Same Email Address

Thank you for thinking along. I'd like to keep it as simple as possible. Let me try to explain it a little.

Think of it as a SaaS platform on which users can register. But their account on client1.domain.tld isn't the same user as client2.domain.tld although their email address can be the same.

Our customer repairs devices and has an online platform to manage that proces. Customers can register their device for repair and create a login for that. Our customer wants to whitelabel the frontend part to other companies, but the devices need to go into the same platform to manage the repairs. A repair customer can have an account at multiple whitelabel without knowing it's actually the same platform.

I hope this clears up my situation...

06 Jun
2 years ago

rikw started a new conversation Seperate Logins On Same Email Address

Hi,

In my project I have separate frontend sections for different clients, but also one for backend. Now I'm looking for a solution to use the same email address for separate users for the different sections. How can I achieve something like that?

As example:

  • domain.tld
  • client1.domain.tld
  • client2.domain.tld
  • backend.domain.tld or domain.tld/backend

The users for client1 & client2 should also have addition fields compare to he user of the main domain.

I'm looking forward to your thoughts. I can't really get my head around it.

06 May
3 years ago

rikw started a new conversation Protect Frontend Controller By Token

Hi,

I'm looking for a way to protect a frontend controller by a token. We want to send customers an email that gives access to a particular record using that token. I saw information about custom guards. Is that the way to go? Or is there a easier way to solve this?

Cheers, Rik

30 Apr
3 years ago

rikw left a reply on Prefered Way To Update A Model

Sweet, thank you both! Works like a charm.

rikw started a new conversation Prefered Way To Update A Model

Dear all,

Being new to Laravel I'm stuggling with a few best practise kind of questions. This one is about the prefered way to update a model. I find myself having two different ways of working for the create and update functions. I expected a Eloquent way of updating. Thanks for looking and helping.

    public function store(Request $request, Offer $offer)
    {
        $this->validate($request, [
            'name' => 'required',
        ]);

        Offer::create([
            'name' => $request->name,
        ]);

        return redirect(route('backend.name.index'));
    }

    public function update(Request $request, Offer $offer)
    {
        $this->validate($request, [
            'name' => 'required',
        ]);

        $offer->name = $request->name;
        $offer->save();

        return redirect(route('backend.offer.index'));
    }

Or, should I do:

    public function update(Request $request, Offer $offer)
    {
        $this->validate($request, [
            'name' => 'required',
        ]);

        Offer::findOrFail($offer->id)->update([
            'name' => $request->name,
        ]);

        return redirect(route('backend.offer.index'));
    }