petritr

petritr

Member Since 6 Months Ago

Experience Points 16,770
Experience Level 4

3,230 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 52
Lessons
Completed
Best Reply Awards 5
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.

14 Feb
1 month ago

petritr left a reply on Condition Inside Query Builder

@bobbybouwmann thanks, we 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_hub', '=', '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 option is equal to 10, not one entry : At the moment it will return only one entry

27 Jan
1 month 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
1 month 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:

{{ service[index] }}

23 Jan
1 month 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

22 Jan
1 month 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 Remox 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
2 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
2 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
2 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
2 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
2 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
2 months ago

petritr started a new conversation Append Data To Nested Array Collection

I need to append data to nested key from collection

the collection 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

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
2 months ago

petritr left a reply on Remove Keys From Collection

@s4muel idk for me didn't work, but it works array_diff() 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 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 was is with:

Arr::pluck($array, 'ring_id'); was is with Arr ?

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 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
    "disabled_ring" => 1
    "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
2 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
2 months ago

petritr left a reply on Push To Collection Key

With Collection ?

petritr started a new conversation Push To Collection Key

Hi have an collection like:

Groups [
        0 => "1"
    1=> "2"
    port [
            0 => "1"
        1=> "2"
    ]
        numbers[
                0 => "1"
                 1=> "2"        
        ]
]

I need to push data to numbers key, i have tried to use pluck to get to the key but not working with numbers key

How can i go to numbers array key then just simply push

02 Jan
2 months ago

petritr started a new conversation Problem Saving Repeated Array

With is the smartest way to save repeated array

array:3 [
  0 => array:5 [
    "port" => array:2 [
      0 => 1417
      1 => 1418
    ]
    "id" => array:2 [
      0 => 154
      1 => 152
    ]
    "name" => array:2 [
      0 => 1
      1 => 1
    ]
    "thing" => array:2 [
      0 => "23"
      1 => "20"
    ]
  ]
  1 => array:5 [
    "port" => array:1 [
      0 => 1425
    ]
    "id" => array:1 [
      0 => 155
    ]
    "name" => array:1 [
      0 => 1
    ]
    "thing" => array:1 [
      0 => "20"
    ]
  ]
27 Dec
2 months ago

petritr left a reply on Database Tables Created Without Migration

The thing is that if Model was created over the terminal with php artisan make:... then the custom tables wont work.

If you create the Model manually then everything works fine you don't need the protected $table variable either. Everything will work the same like when you do the migration.

21 Dec
2 months ago

petritr left a reply on Database Tables Created Without Migration

Okay i found out i need to disable timestamps tables since i don't have timestamps columns for this table.

petritr left a reply on Database Tables Created Without Migration

basically my question is can i create the table without using migration manually ? If so do i need to tell my Model witch table so use or any other thing ?

petritr left a reply on Database Tables Created Without Migration

not working with protected $table

petritr started a new conversation Database Tables Created Without Migration

I have one simple question, how can i tell my Model witch database table it belongs, when the table is created without using migration.

Because i cant save data to the table.

18 Dec
3 months ago

petritr left a reply on Where Condition With Related Data

        Users::with(['branch', 'jobs' => function($query)   {
            $query->where('job_type', '=', 'IT')->orWhere('job_type', '=', 'Other');
        }])->get();

petritr left a reply on Where Condition With Related Data

@globals again not now its sending all related data without the whereHas condition. Basically as i had before.

petritr left a reply on Where Condition With Related Data

@globals not doing the what i need, i need to get the relation data too.

petritr left a reply on Where Condition With Related Data

@munazzil very good :D Users::with('job')->get(); what do you think what does this ?

petritr started a new conversation Where Condition With Related Data

I need to do an where condition in query.

Users::with('job')->get();

This will get all Users with related jobs, i need to do where condition like: where jobs position is equal to IT. How can i do where condition for related data.

17 Dec
3 months ago

petritr left a reply on Add Offset To Pagination

@aurawindsurfing yes of course

        props: ['meta_data', 'offset'],
        methods: {
            isCurrentPage(page) {
                return this.meta_data.current_page === page;
            },
            changePage(page) {
                this.$emit('next', page);
            }
        },
        computed: {
            pages() {
                let pages = [];
                let from = this.meta_data.current_page - Math.floor(this.offset / 2);
                if (from < 1) {
                    from = 1;
                }
                let to = from + this.offset - 1;
                if (to > this.meta_data.last_page) {
                    to = this.meta_data.last_page;
                }
                while (from <= to) {
                    pages.push(from);
                    from++;
                }
                return pages;
            }
        },

html

            <li class="pagination-item" v-for="page in pages">
                <a class="page-link" :class="isCurrentPage(page) ? 'active' : ''" @click.prevent="changePage(page)">{{ page }}</a>
            </li>

Parent component

            <pagination :offset="10" :meta_data="meta_data" v-on:next="fetchLogs"></pagination>