petritr

petritr

Member Since 4 Months Ago

Experience Points 13,290
Experience
Level
Lessons Completed 21
Lessons
Completed
Best Reply Awards 5
Best Answer
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.

15 Jan
1 day 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 days 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
3 days 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
6 days 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
1 week 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
1 week 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
1 week 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
1 week 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 weeks 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 weeks 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
3 weeks 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
4 weeks 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
4 weeks 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>

petritr left a reply on Add Offset To Pagination

@aurawindsurfing

i don't mix anything my question was how to make the offset in vue, i use the laravel pagination.

i fond an solutions, thanks for offering help :)

14 Dec
1 month ago

petritr started a new conversation Add Offset To Pagination

I have the following

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

How can i add offset to my pagination so i got 5.. 6 7 8 .. 9

Any help with this

12 Dec
1 month ago

petritr left a reply on Check If Input Value Before Update

@lostdreamer_nl yes is dirty works fine i though about that too.

Thank you!

petritr left a reply on Check If Input Value Before Update

I can hit the save button without editing any input the update controller is returning me the success message

petritr started a new conversation Check If Input Value Before Update

Witch is the best way to check for input value and compare them with the database values, if the input value is the same with the database value don't update. If the inputs values are different den update only the different inputs.

Can this be done with validation or? Witch is the best way to do it?

petritr left a reply on $ Is Not Defined At.. Blade Template

@globals nope won't work, i removed the defer from jquery not working either.

petritr left a reply on $ Is Not Defined At.. Blade Template

I think blade don't know that i have included jquery

the problem should be here

        <script src="{{ asset('js/jquery-3.3.1.min.js') }}" defer></script>

When i do this:


@section('scripts')
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script>
        $( document ).ready(function() {
            $('#messageModal').modal('show');
        });
    </script>
@stop

Then it works, any ideas ?

petritr left a reply on $ Is Not Defined At.. Blade Template

I m big fan of defer and async, the page will load and wont wait for complete js loading

petritr left a reply on $ Is Not Defined At.. Blade Template

   @yield('scripts');

        <!-- Scripts -->
        <script src="{{ asset('js/jquery-3.3.1.min.js') }}" defer></script>`

petritr started a new conversation $ Is Not Defined At

I have the following:

On my view

@section('scripts')
    @if (session('status'))
    <script>
            $('#messageModal').modal('show');
            console.log('HAHAH');
    </script>
    @endif
@stop

In my master layout i have @yield('scripts');

The console log works but the $ Jquery not working what i do wrong ?