rikw

Experience

1,430

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 6 Lessons Completed
  • 0 Favorites

6th December, 2017

rikw started a new conversation Object Oriented Components • 6 days ago

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!

5th December, 2017

rikw left a reply on Convert Collection Into Formatted Array (refactor) • 6 days ago

Sweet, thanks!

rikw started a new conversation Convert Collection Into Formatted Array (refactor) • 6 days ago

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,
        ];
    }

10th November, 2017

rikw left a reply on Working With Many-to-many Relations - Filters And Roles • 1 month ago

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 • 1 month ago

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?

9th November, 2017

rikw started a new conversation Working With Many-to-many Relations - Filters And Roles • 1 month ago

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

5th September, 2017

rikw started a new conversation Type Based Tasks • 3 months ago

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

9th August, 2017

rikw started a new conversation Creating Complex Layouts • 4 months ago

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 • 4 months ago

@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 • 4 months ago

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!

13th June, 2017

rikw left a reply on Writing Tests For SSH • 5 months ago

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

9th June, 2017

rikw started a new conversation Writing Tests For SSH • 6 months ago

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?

8th June, 2017

rikw left a reply on How To Work With Fixed State/status/type Fields • 6 months ago

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.

7th June, 2017

rikw left a reply on How To Work With Fixed State/status/type Fields • 6 months ago

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 • 6 months ago

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!

2nd August, 2016

rikw left a reply on Date Field Shown As -0001-11-30 00:00:00 • 1 year ago

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.

1st August, 2016

rikw started a new conversation Date Field Shown As -0001-11-30 00:00:00 • 1 year ago

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

8th June, 2016

rikw left a reply on Seperate Logins On Same Email Address • 1 year ago

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

7th June, 2016

rikw left a reply on Seperate Logins On Same Email Address • 1 year ago

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 • 1 year ago

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 • 1 year ago

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...

6th June, 2016

rikw started a new conversation Seperate Logins On Same Email Address • 1 year ago

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.

6th May, 2016

rikw started a new conversation Protect Frontend Controller By Token • 1 year ago

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

30th April, 2016

rikw left a reply on Prefered Way To Update A Model • 1 year ago

Sweet, thank you both! Works like a charm.

rikw started a new conversation Prefered Way To Update A Model • 1 year ago

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'));
    }
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.