jay_gorio

jay_gorio

Member Since 4 Years Ago

Experience Points
8,630
Total
Experience

1,370 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
60
Lessons
Completed
Best Reply Awards
0
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 2
8,630 XP
Oct
07
2 months ago
Activity icon

Started a new Conversation Double Entry Accounts For Payment Of Tuition Fees

A student has total tuition fee of 8,000. The student paid 3,000 as a down payment and the journal entry is:

Cash 3,000
AR   5,000
     Tuition Fee  8,000

But what if the student will pay 3,500 for the next payment, what would be the journal entry? Is this correct?

Cash 3,500
AR   4,500
     Tuition Fee  8,000
Jul
15
4 months ago
Activity icon

Replied to Flatten Laravel Nested Relationship (parent To Descendants)

The problem with this, is that it will fetch all children not related to parent. But it definitely flatten the collection

Activity icon

Replied to Flatten Laravel Nested Relationship (parent To Descendants)

I just used your suggestion I am getting unknown method for values().

Activity icon

Replied to Flatten Laravel Nested Relationship (parent To Descendants)

Yes it return as a Collection. I made use of all the option you have given. since the And the pluck accepts the array as a paramter. But it gives me null output for each item. (See code below) But when passing only one parameter (e.g. name) It gives me result.

Collection {#295
  #items: array:6 [
    0 => null
    1 => null
    2 => null
    3 => null
    4 => null
    5 => null
  ]
}
Activity icon

Replied to Flatten Laravel Nested Relationship (parent To Descendants)

Here is the code.

$parent = $parent->with('descendants')->find($parent->id);

dd($parent->pluck(['name', 'address', 'contact_no', 'id']));
Activity icon

Replied to Flatten Laravel Nested Relationship (parent To Descendants)

This is the error.

exception: "ErrorException"
file: "C:\laragon\www\gawisorg\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php"
line: 1047
message: "stripos() expects parameter 1 to be string, array given"
Activity icon

Replied to Flatten Laravel Nested Relationship (parent To Descendants)

Based on the laravel 5.8 documentation the pluck only takes string as its first parameter

    /**
     * Get an array with the values of a given key.
     *
     * @param  string  $value
     * @param  string|null  $key
     * @return \Illuminate\Support\Collection
     */
    public function pluck($value, $key = null)
    {
        return $this->toBase()->pluck($value, $key);
    }
Activity icon

Replied to Flatten Laravel Nested Relationship (parent To Descendants)

@mstrauss Yes this works. But it is only limited with one column of table.

[
   {
      'name': 'Parent',
      'children': [
         {
             'name': 'First Child',
             'address': 'lorem ipsum',
             'contact_no': '92390',
             'children': [
                {
                    'name': 'First Descendant',
                    'address': 'lorem ipsum',
                    'contact_no': '92390',
                    'children': [
                        {
                            'name': 'Descendant Child',
                            'address': 'lorem ipsum',
                            'contact_no': '92390',
                            'children': [
                                {
                                   'name': 'Last Descendant',
                                   'address': '',
                                   'contact_no': '',
                                   'children': []
                                }
                            ]

                        }
                    ]
                }
             ]
         }
      ]
   }
]

Desired Output


    [
        {
            'name': 'Parent',
            'address': 'lorem ipsum',
            'contact_no': '92390'
        },
        {
            'name': 'First Child',
            'address': 'lorem ipsum',
                 'contact_no': '92390'
        },
        {
            'name': 'First Descendant',
            'address': 'lorem ipsum',
                 'contact_no': '92390',
        },
        {
            'name': 'Descendant Child',
            'address': 'lorem ipsum',
                 'contact_no': '92390',
        },
        {
            'name': 'Last Descendant' ,
            'address': '',
                 'contact_no': '',
        }
                
    ]

Activity icon

Started a new Conversation Flatten Laravel Nested Relationship (parent To Descendants)

I have a parent children relationship on my model. What I want is to flatten all those collection including all those descendants of parent.

[
   {
      'name': 'Parent',
      'children': [
         {
             'name': 'First Child',
             'children': [
                {
                    'name': 'First Descendant',
                    'children': [
                        {
                            'name': 'Descendant Child',
                            'children': [
                                {
                                   'name': 'Last Descendant',
                                   'children': []
                                }
                            ]

                        }
                    ]
                }
             ]
         }
      ]
   }
]


I tried the code below. However it only displays the second depth of children. It does not display the next children of the collection.

User.php
public function parent()
{
    return $this->belongsTo(User::class, 'id', 'parent_id');
}

public function children()
{

    return $this->hasMany(User::class,'parent_id', 'id');
}

public function descendants()
{
    return $this->children()->with('descendants');
}

UsersController.php

public function index()
{
    $parent = User::find(1);

    $parent->with('descendants')->find($parent->id);

    $descendants = $this->traverseTree($parent->descendants);

    return response($descendants);
}

protected function traverseTree($subtree)
{
    $descendants = collect([]);

    foreach ($subtree->descendants as $descendant) {
            
       $descendants->push($descendant);

       if($descendant->descendants instanceof Collection) {

          foreach ($descendant->descendants as $node) {
                    
             $this->traverseTree($node);

             $descendants->push($node);
          }
       }
   }

   return $descendants;
}

Desired Output

[
    {
        'name': 'Parent'
    },
    {
        'name': 'First Child'
    },
    {
        'name': 'First Descendant'
    },
    {
        'name': 'Descendant Child'
    },
    {
        'name': 'Last Descendant' 
    }
            
]

I am looking forward for your help.

Jul
09
5 months ago
Activity icon

Replied to How To Place Node On Specific Position(left/right) Using Laravel-nestedset

Thank you for your response. That is why I like the package it has a lot of convenience. However, based on your answer and the documentation itself, user has no control of manually assigning the node position. Anyways thank your for the reference.

Jul
06
5 months ago
Activity icon

Replied to How To Construct A Binary Tree?

Thanks for your reply. Yeah that's the limitation of the package. Thank you for your suggestions. I am creating a multi level marketing (binary) and it seems I cannot find solution on how to implement its feature. Do you have any suggestion on how to implement this.

Jul
05
5 months ago
Activity icon

Started a new Conversation How To Construct A Binary Tree?

How can we build a binary tree?

For example if the left and right child is empty find the next left empty child and append there?

Is that possible using lazychaser/laravel-nestedset package?

Activity icon

Started a new Conversation How To Place Node On Specific Position(left/right) Using Laravel-nestedset

I am using the package laravel-nestedset for my multi level marketing(binary) system. However I cannot figure it out how to append the node to specific position.

Let's say for example:

$parent = User::find(1);
$child = User::create(['name' => 'Child', 'username' => 'child1']);
$parent->appendNode($child);

The output will be:

{
        id:1,
        name: 'Parent',
        parent_id: null,
        _lft: 1,
        _rgt:4,
        'username': 'parent1',
        'children: [
            {
                id:2,
                name : 'Child',
                username: 'child1',
                _lft: 2,
                _rgt: 3,
                parent_id: 1
            }
        ]
}

How do I know if the node is positioned on left or right? And what if I only want to fetch the children of parent based on left position?