petritr

petritr

Member Since 1 Year Ago

Experience Points
25,920
Total
Experience

4,080 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
139
Lessons
Completed
Best Reply Awards
5
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 6
25,920 XP
17 Sep
3 days ago

petritr started a new conversation Storing And Delaying An Transaction

Is there a way to store the transaction and wait for an user confirmation ? If the confirmation is true then execute the transaction?

Something like send an warning and wait for confirmation

11 Sep
1 week ago

petritr started a new conversation Laravel Model Observers & Relations

Is it a good price to use Observers to check when an relationship HasMany is created? My goal is to know when an relationship is created so i can check the other Model and update it with the relation data.

I want to Observe when Users has and Job Relation created, with the Job data i can check if Position Model has this new Job

Any suggestions ?

08 Sep
1 week ago

petritr started a new conversation Group Nested Array By Same Value

I have an nested array like this:

array:4 [▼
  0 => array:4 [▼
    "id" => 9
    "position" => 3
    "jobs" => array:2 [▼
      0 => array:21 [▼
        "id" => 2
        "name" => "9987C"
        "plan_id" => null
      ]
      1 => array:21 [▼
        "id" => 3
        "name" => "1009V"
        "plan_id" => null
      ]
    ]
  ]
  1 => array:4 [▼
    "id" => 8
    "position" => 2
    "jobs" => array:1 [▼
      0 => array:21 [▼
        "id" => 2
        "name" => "10bb"
        "plan_id" => null
      ]
      1 => array:21 [▼
        "id" => 4
        "name" => "CC09"
        "plan_id" => null
      ]
    ]
  ]
  ...

i need to group same nested array from jobs with the same id like:

array:4 [▼
   8 => array:4 [▼
     "id" => 8
     "position" => 2
   ]
    "id" => 9
    "position" => 3
    "jobs" => array:3 [▼
      0 => array:21 [▼
        "id" => 2
        "name" => "01"
        "plan_id" => null
      ]
      1 => array:21 [▼
        "id" => 3
        "name" => "09BB"
        "plan_id" => null
      ]
      3 => array:21 [▼
        "id" => 4
        "name" => "10CB"
        "plan_id" => null
      ]
    ]
  ]

i have problem checking the same jobs id inside the foreach:

$finalJobs = array();

       foreach ($CompleteJobs as $index => $jobs) {
            foreach ($jobs['jobs'] as $job) {

                if (!empty($finalJobs)) {
                    foreach ($finalJobs as &$finalJob) {
                        foreach ($finalJob['jobs'] as $Fjob) {
                           if (!empty(array_intersect($Fjob, $job))) {
                             //here is my problem
                            }
                        }
                    }
                } else {
                    $finalJobs[$job['id']] = $job;
                }

            }
        }

any help ?

03 Sep
2 weeks ago

petritr left a reply on Filter Duplicated Array Collections

wont work directly with unique since its a nested array collection

petritr started a new conversation Filter Duplicated Array Collections

I have an collection like this:

Collection {#560 ▼
  #items: array:3 [▼
    429 => array:3 [▼
      0 => array:5 [▼
        "id" => 1242
        "post_id" => 2040
        "post" => array:21 [▶]
      ]
      1 => array:5 [▼
        "id" => 1245
        "post_id" => 2047
        "post" => array:21 [▶]
      ]
    ]
    430 => array:3 [▼
      0 => array:5 [▼
        "id" => 1243
        "post_id" => 2040
        "post" => array:21 [▶]
      ]
    431 => array:3 [▼
      0 => array:5 [▼
        "id" => 1245
        "post_id" => 2041
        "post" => array:21 [▶]
      ]
      1 => array:5 [▼
        "id" => 1244
        "post_id" => 2047
        "post" => array:21 [▶]
      ]
    ]
  ]
}

if the post_idlike 2040 and 2047 from array 429 is found in the other array 431 then return only the only array 431 so i would have the duplicated removed

14 Aug
1 month ago

petritr left a reply on Unit Test Relations

Yes i need to check the relation between them HasOne or BelongsTo etc @tykus ?

petritr left a reply on Unit Test Relations

@tykus i have this relations Users with Plan, Plan with Plan Assignment, Plan with Region, Region with program

It better do insert the relations in the factory, or do the test manually check the relations column ids? Or What do you recommend for unit tests ?

petritr started a new conversation Unit Test Relations

I have complex relations, witch is the best way to test relations ? Any best practice examples ?

01 Aug
1 month ago

petritr left a reply on Validation Exception

@tykus thanks for the idea, the failedValidation should i override in a new handler or?

petritr left a reply on Validation Exception

@tykus i would like to continue the methode and store the changes with the warning showed in front end as warning popup(send from backend like json error message), with the rest of the errors stop and catch the exception.

petritr started a new conversation Validation Exception

I need to allow some validation error to be displayed as warning not like error, how can i do that? With custom validation exception or?

I have a custom Request with custom Rule, i need to allow only one case as warning and display it as warning not really like error, the rest of the cases i need to display then like its now like real error.

23 Jul
1 month ago

petritr started a new conversation Filter Model Entry Laravel Collection

I need to go though each entry where some condition it meet.

I have all conditions in an extra array, the array can have more or few keys:

 array:2 [
  "date" => "true"
  "column" => 1
....
]

I would need to filter all Model entry's where implementation_date is not null and column is 1

$allUsers = Users::all();
        foreach ( array_keys($arrayColumns) as $key ) {
            if ($key === 'column' || $key === 'Two' || $key === 'Three') {
        $allUsers->where($key, 1)
        }
            if ($key === 'date' || $key === 'dateTwo' ) {
        $allUsers->where($key, '!=',null)
        }
    }

$allUsers->all();

I would like to habe something like the above but its not really working the where

22 Mar
5 months ago

petritr started a new conversation Automatically Deploy Npm Compiled Files

I look for a way to automatically deploy compiled public css and js files to an remove server.

Look for npm package or bash script windows env, let me know any suggestions.

14 Feb
7 months ago

petritr left a reply on Condition Inside Query Builder

@bobbybouwmann thanks, how can i use this with 2 relations:

Job::where('disabled_hub', '=', '0')->with(['positions' => function ($queryPositions) {
            $queryPositions->where('queryPositions', '=', '10') );
        }, 'locations' => function ($queryLocations) {

How can i use that inside locations i need to have an condition like where inside region is equal to US Return all locations

petritr started a new conversation Condition Inside Query Builder

I need to have an condition inside an relation query builder

 $jobs = Job::where('disabled_job', '=', '0')->with(['positions' => function ($queryPositions) {
       if(  $queryPositions->where('option', '=', '10')) ) {
            //Here i need again all $jobs 
       }

I need to write an condition then retrieve all jobs where option is equal to 10, not one entry.

At the moment it will return only one entry

27 Jan
7 months ago

petritr started a new conversation Vuelidate Validate Nested Object Array

I want to validate an object array inside nested object array

FormData:Array[8]
0:Object
    group:Object
        id:1
        cards:Array[8]
            0:Object
            id:2253
                service:Object
                    name:"Service Name"
....

I need to validate from service only the name

I try with something like this, but no success...

validations() {
            return {
                FormData: {
                    $each: {
                        group: {
                            cards: {
                                $each: {
                                    service: {
                                        name: {
                                            required
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

Any help with this vuelidation package ? Here is an example from the official package: https://monterail.github.io/vuelidate/#sub-collections-validation

26 Jan
7 months ago

petritr started a new conversation Vue Getter, Setter With Array

I need to get and then set new values(array) but it doesn't seems like get and set is working with array, any ideas how to do this smart?

My array looks like:

services:Array
0: name:"SS"
1: name:"SS"
2: name:"SS"
3: name:"SS"
....

My computed:

Megaherz: {
                get: function(index) {
            return (I need to get this array from database same structure)                    
                },
                set: function(newValue) {
            //Set new value for each array 
                },
            }

I want to use it like: <p v-for="(service, index) services">{{ service[index] }}</p>

23 Jan
7 months ago

petritr started a new conversation Vuex Store With Id

How can i fetch particular id that is passed to axios

i have the following:

                 axios.get('/api/url/' + this.id).then(({data}) => {
                    this.urldata = data;

                    }
                });

how ca i pass the this.id in vuex store method ? this.id property is from my component

Could i send the my property with this.$store.dispatch('Loaddata', this.id) or ?

petritr started a new conversation Diff In Multidimensional Array Collection

How can i get the difference between 2 multidimensional collection

` dd(collect($aTmpboth2)->collapse()->toArray());``will print out

array:10 [
  0 => array:1 [
    "id" => 2
  ]
  1 => array:1 [
    "name" => 32
  ]
  2 => array:1 [
    "id" => 33
  ]
  3 => array:1 [
    "name" => 32
  ]
....
]

i have another collection like this, when i try dd($aTmpboth1->diff(aTmpboth2)); i get back array to string conversion error

22 Jan
7 months ago

petritr left a reply on Remove Keys From Collection

@hasansemih not working wither, showing the original collection back

petritr left a reply on Remove Keys From Collection

@rodrigo.pedra wont return the duplicates, i need the duplicates also

petritr started a new conversation Remove Keys From Collection

How can i remove the keys from collection

my collection :

Collection {#962
  #items: array:6 [
    0 => array:2 [
      "id" => 1
      "log" => 2
    ]
    1 => array:2 [
      "id" => 1
      "log" => 32
    ]
    2 => array:2 [
      "id" => 2
      "log" => 33
    ]
    3 => array:2 [
      "id" => 2
      "log" => 32
    ]
....
  ]
}

How can i remove the key and have the collection like

      "1" => 1
      "1" => 2
      "3" => 1
      "3" => 2
    ...
17 Jan
8 months ago

petritr started a new conversation Vuex Store (state Undefined)

I have problem while setting up VueX Store

My Store:

import Vuex from 'vuex';

const store = new Vuex.Store({
    state: {
        items: [],
    },
    actions: {
        LoadItems({commit}) {
            axios.get('/api/items').then(({response}) => {
                commit('SetItems', response.data)
            });
        }
    },
    mutations: {
        SetItems(state, items) {
            state.items= items
        }
    }
});

On my component i have the following:

    import { Store} from ../Store'

        computed: {
            items() {
                return this.$store.state.items;
            }
        },

It returns an error: [Vue warn]: Error in render: "TypeError: Cannot read property 'state' of undefined"

What im doing wrong here ?

15 Jan
8 months ago

petritr left a reply on Access Child Initial Data From Parent Component

@realrandyallen any example with this.$children i have not done this before.

Basically i need to access each child data initial data. There are objects with can change. I need to access the initial data from each child component inside the v-for

I have emits and props, what i need now is to have the initial data from child components to be able to have reset functionality.

Thank you!

petritr left a reply on Access Child Initial Data From Parent Component

@realrandyallen

Would this work fine with v-for repeated child components? If you can please let me now witch are the alternatives ? Thank you!

petritr started a new conversation Access Child Initial Data From Parent Component

i need something like:

$vm.$options.data

Is there any smart way to access child initial data from parent component? something like: $vm.$chldren.$options.data()

Or there is something else ?

petritr started a new conversation Delay Vue Watcher Until A Property Is Set?

I need to wait for property to be set on created then watch.

data() {
            return {
                data: null,
            }
        },

created() {
                 axios.get('/api/data/' + ).then(({data}) => { 
            this.data = data
        }
}
watch: { 
            'data': function(newVal, oldVal) {
                    if (oldVal && newVal) {
                        let changedVal = 'Change is made';
                    }
                }
            },
}

I need do Delay the watch until this.data is set, any ideas how to do this ?

14 Jan
8 months ago

petritr left a reply on Show New And Old Attributes

@snapey yes i have seen that and i wrote on my question also. Is there any other way except getOriginal

petritr started a new conversation Show New And Old Attributes

With is the best way to show old and new changed model data ?

I have seen eamples with getOriginal or ?

I need to show only the changed fields with new and old value

13 Jan
8 months ago

petritr started a new conversation Validation With Vuelidate

Has anyone used vulidation package for validation ? I have problem validating emited array. Any help ?

10 Jan
8 months ago

petritr left a reply on Push To Nested Array

You mean the $Groups I need to new pushed valuies to $Groups` array

petritr left a reply on Push To Nested Array

@vlad_kash and @palak27 LOL thats my loop, i need to return the complete array with the append data

petritr started a new conversation Combine 2 Arrays Of Different Lengths

How can i combine 2 different lengths array:

I want to combine this array:

array:1 [▼
  "services" => array:5 [▼
    0 => Collection {#1371 ▼
      #items: array:7 [▼
        "id" => 241
        "service" => 1
        "name" => "First Service"
      ]
    }
    1 => Collection {#1623 ▼
      #items: array:7 [▼
        "id" => 247
        "service" => 2
        "name" => "Second Service"
      
...

With my main nested array where there is no name key for services with i want to append to my main array

array:8 [▼
  0 => array:6 [▼
    "id" => 784
    "group" => "1"
    "port" => array:8 [▼
      0 => array:4 [▼
        "id" => 1785
        "port" => "1"
        "services" => array:6 [▼
            "id" => 247
            "service" => "1786"
        ]
      ]

My goal is push the name key to my original nested array, How can i combine both arrays or if there an smarter say ?

petritr left a reply on Append Data To Nested Array Collection

@burlresearch im struggling with the keys here cant get to port with groups.7.port How does this works exaclty i have seen also * selection

petritr left a reply on Append Data To Nested Array Collection

@burlresearch more detailed example im stuck here. :/

petritr started a new conversation Push To Nested Array

I need to push data to nested array, then return the complete data with the new appended data.

How can i return the original nested array with the new data inside ?

    0 => array:6 [▼
      "id" => 784
      "group" => "1"
      "port" => array:8 [▼
        0 => array:4 [▼
          "id" => 1785
          "port" => "1"
          "services" => array:6 [▼
            "id" => 241
            "service" => 1785
          ]

I go through the array :

        foreach ($Groups as $Group) {
            foreach ($Group['port'] as $item) {
                if ( ($item['services']) ) {
                    array_push($item['services'], 'name');
                    var_dump($item['services']);
                }
            }
        }

the var_dump($item['services']); will return the service with the data

array (size=7)
    "id" => 241
     "service" => 1785
     0 => string 'name' (length=4)

I need to return the appended data to the original array, how can i do that?

09 Jan
8 months ago

petritr started a new conversation Append Data To Nested Array Collection

I need to append data to last nested key from collection

the collection array looks like:

array:16 [▼
  "id" => 387
  "comment" => null
  "created_at" => "2019-01-04 13:51:04"
  "updated_at" => "2019-01-06 14:39:52"
  "groups" => array:8 [▼
    0 => array:6 [▼
      "id" => 784
      "group" => "1"
      "port" => array:8 [▼
        0 => array:4 [▼
          "id" => 1785
          "port" => "1"
          "group_id" => 784
          "service" => array:6 [▼
            "id" => 241
            "port_id" => 1785
          ]
        ]

I need to append to the last nested array key service

i can access service array key but i will lose the structure of the array with get() then pluck()

Also I need to check if service is not null then append name key with some data

Is there a smarter way to append data to last nested array without losing the structure of the collection?

petritr started a new conversation Find Key With Data In Nested Collection Or Array

I have nested collection or array(i can convert the collection to array) like :

array:16 [▼
  "id" => 387
  "comment" => null
  "created_at" => "2019-01-04 13:51:04"
  "updated_at" => "2019-01-06 14:39:52"
  "groups" => array:8 [▼
    0 => array:6 [▼
      "id" => 784
      "group" => "1"
      "port" => array:8 [▼
        0 => array:4 [▼
          "id" => 1785
          "port" => "1"
          "group_id" => 784
          "service" => array:6 [▼
            "id" => 241
            "port_id" => 1785
          ]
        ]

I need to find the service array or collection with data, if its not null then append some data. How can i find array key with data without using foreach or for loops.

I have send the data as array but i have them as collection too.

08 Jan
8 months ago

petritr left a reply on Remove Keys From Collection

@s4muel idk for me didn't work, but array_diff() works witch returns what i need

petritr started a new conversation Cache Db Queries

Witch is the best way to cache external second msql connection ?

To cache each method or ? Any ideas for caching ?

petritr left a reply on Remove Keys From Collection

@tykus i want to use diff from collection methods. From what i tired the dif methods worked only with array without keys, but i ended up using the php array_diff

If you have suggestion please let me know, thanks!

petritr left a reply on Remove Keys From Collection

@manelgavalda i don't want an array i need to remove the keys form collection

petritr left a reply on Remove Keys From Collection

@tykus already tried not working:

                $pluckedRings = $ringsCollection->pluck('id');
                dd($pluckedRings->values());

will return

Collection {#971
 #items: array:3 [
   0 => 2
   1 => 10
   2 => 25
 ]
}

petritr started a new conversation Remove Keys From Collection

I have collection with Multidimensional Array:

Collection {#970
  #items: array:3 [
    0 => 2
    1 => 10
    2 => 25
  ]
}

I want to remove the keys and have the collection like:

[2,10,25]

How can i remove the keys from collection ?

petritr left a reply on Get Difference From Object And Array

@adamprickett i get back

message: "Array to string conversion"

petritr left a reply on Get Difference From Object And Array

@snapey when i try in_array i get back Std class object. I have collection of Std class object What would you suggest to do ? How can i check for different array element in Std class object ?

petritr left a reply on Get Difference From Object And Array

@palak27 i need to check object if in object exists this array value

petritr started a new conversation Get Difference From Object And Array

Witch is the best way to get the difference from object and array(i need to find witch ring_id is not in both object and array)

my object:

Collection {#779
  #items: array:2 [
    0 => {#776
      +"id": 270
      +"ring_id": 25
    }
    1 => {#777
      +"id": 271
      +"ring_id": 2
    }
  ]
}

Array:

array:1 [
  0 => array:11 [
    "id" => 10
    "ring_id" => 2
    "ring_name" => "Ring Name"
    "comment" => null
    "created_at" => "2018-12-10 09:17:22"
    "updated_at" => "2018-12-10 09:18:24"
  ]
]

How can i get the different ring_id that don't exist in the array ?

06 Jan
8 months ago

petritr started a new conversation Loop Though Model Data

Witch is the best way to loop though model data and push data to particular key.

I have data like:

Device {#795 ▼
  #primaryKey: "id"
  #fillable: array:11 [▶]
  #connection: "mysql"
  #table: null
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:14 [▶]
  #original: array:14 [▶]
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: array:2 [▶]
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [▶]

array I need to go though relations data and push data to relation key array

04 Jan
8 months ago

petritr left a reply on Push To Collection Key

With Collection ?