binggle

Member Since 3 Years Ago

Experience Points
5,690
Total
Experience

4,310 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
29
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

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

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 2
5,690 XP
Jan
15
22 hours ago
Activity icon

Replied to Livewire / Pagination / Child Component Work Wrong.

If you mean using 'WithPagination' trait, I did.

use WithPagination; 

is declared in ParentComponent ..

Activity icon

Replied to Livewire / Pagination / Child Component Work Wrong.

Thanks for reply..

But I dont get your points.

Can you explain more in detail?

Actually I don't see the difference between livewire pagination and regular pagination.

The code looks same.

Can you?

Activity icon

Started a new Conversation Livewire / Pagination / Child Component Work Wrong.

hi..

I found Livewire Pagination reacts wrong with children's 'emit' event..

I have Two Livewire components.

'ParentComponent' embrace 'ChildComponent' .

In ChildComponent I do something and trigger 'updated' event '

So ParentComponent grab the 'updated' event.

After grabbing event, refreshing list datatable and clicking page 2, the pagination url goes wrong.

The url path goes 'http://example.test/livewire/message/admin.tables.videos?cat_id=3&page=2' ...

actually its url was 'http://example.test/admin/videos?cat_id=3' .

It should go to 'http://example.test/admin/videos?cat_id=3&page=2' .

And It showes this error message on browser.


Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: POST.

Can someone explain what is going on ?

Check my code.

I made code simplified for easy catch.

ParentComponent.php

protected $listeners = [
    'updated' =>'$refresh'
];

function render(){
    $items = Item::paginate();
    return view('livewire.parent', [
            'items'=> $items,
        ]);
}

in livewire/parent.blade.php

<div>
    @livewire('child-component')

    @foreach ($items as $item)
<div>        {{ $items->title}}</div>

    @endforeach

    <div >
        {{ $items->appends( $_GET )->links() }}
    </div>
</div>

ChildComponent.php

function render(){
    return view('livewire.child');
}

function saveForm(){
    // ... save data .doing something..
    $this->emit('updated')
}

in livewire/child.blade.php

<form wire:submit.prevent='saveForm'> -->
    <input  ... />
    <button type="submit" > OK </button>
</form>

Jan
13
2 days ago
Activity icon

Started a new Conversation How To Call Alpine JS Method From Livewire?

hi

I want to run alpinejs function from livewire component.

in posts component,

function gotcomment(){
    $this->emit('gotcomment');
}

in posts view

<div wire:click="gotcomment">
    I will get post
</div>

in blade.

<div x-data="myfunction()">
    @livewire('posts')
</div>

<script>
    window.livewire.on('gotcomment', () => {
        console.log( '----')
        this.callme() ; --> it goes error ..
    });

    function myfunction() {
        return {
            callme() {
                console.log('callme')
            },
        }
    }
</script>

this.callme() is not run..

How can I fire alpinejs function from livewire ?

Jan
12
3 days ago
Activity icon

Replied to Getting The Last Records From Many To Many Relationship.

thank you for reply.

So It is impossible with Eloquent model , isn't it?

Activity icon

Replied to Getting The Last Records From Many To Many Relationship.

Sorry. that is not about many-to-many.

Activity icon

Started a new Conversation Getting The Last Records From Many To Many Relationship.

I have two models , Category / Video .

It has many-to-many relationship.

See models.

Category.php

class Category extends Model
{
    public function videos()
    {
        return $this->belongsToMany(Category::class, 'category_video' );
    }
}

Video.php

class Video extends Model
{
    public function categories()
    {
        return $this->belongsToMany( Category::class, 'category_video' );
    }

    public function last_video()
    {
        return $this->videos()
                ->withPivot(['created_at'])
                ->orderBy('pivot_created_at','desc')
                ->withTimestamps();
                // ->first(); --> it Goes error 
    }
}

I want to get the latest videos at each categories.

    $cats = Category::with('first_video')
                ->get();;

Not working.

I can not find any ref for this.

Can someone help me ?

Jan
10
5 days ago
Activity icon

Replied to How To Validate Input Value In Livewire?

Thanks for reply.

Cause Livewire is a kind of ajax system, every input variables need to be checked.

Yes you are right, I don't have to separate two funtions but What I curious is how to validate variables in case several user clicks or actions with variables are mixed in one component-view .

As you recommended.


function thumbsUp( $video_id ){
    // just increase thumbs counter for this video
}


function thumbsDown( $video_id ){
    // just increase thumbs counter for this video
}

There is two functions but there is $video_id variable to be validated .

Actually I think the $video_id variable should be checked by validation rule.

I know there is is 'protected $rules ' in component . and that '$rules' is for form-submit action only ( I guess ).

And It is not for all clicks/actions.

The $video_id can not be declared with public variable, Cause it is given by foreach loop of 'videos' collections.

And I can not validate $video_id with updatingVideoId / updatedVideoId events cause the variable is not given by user.

So I guess there could be another validation way to check for every/any user clicks or actions.

I just want to validate all inputs variables even though it is given from views.

I hope you understand what I try to do.

Activity icon

Started a new Conversation How To Validate Input Value In Livewire?

I want to make Up/Down buttons working.

Please check my code it is so simple ..

in view

<div wire:click="ThumbsUp( $video_id, 'up' )" >
ThumbUp
</div>

<div wire:click="ThumbsDown( $video_id, 'down' )" >
Thumb Down
</div>

in livewire component.

function thumbsUp( $video_id, $up_down ){
    $validatedData = $this->validate([
        'video_id' => ['required', 'integer'],
        'up_down' => ['required', 'in:up,down'],
    ]);
}


function thumbsDown( $video_id, $up_down ){
    // ... same with up 
}


It goes error.

        Exception
No property found for validation: [video_id]
// or without video_id 
No property found for validation: [up_down]


I guess I don't need forms.

and it should be two forms if used. So

protected $rules = [] ;;

Would not useful.

How to validate input in livewire component ?

Jan
08
1 week ago
Activity icon

Started a new Conversation How To Make Unique User Without Login ?

Hi.

I want to discriminate users even without login .

Maybe IP and browser would be used.

Can I get any information more about this case ?

Jan
07
1 week ago
Activity icon

Replied to Something Like 'hasManyThrough' For HasMany / BelongsToMany ( Many-To-Many ) Grandchild Relation ?

'Do you want to be able to get a count of how many videos exist under a certain category with a specific alphabet?' --> yes.

I guess 'constraining-eager-loads' is not related with my case.

Thanks.

Activity icon

Replied to Something Like 'hasManyThrough' For HasMany / BelongsToMany ( Many-To-Many ) Grandchild Relation ?

Thanks for info.

I see some similar case in eloquent-has-many-deep package.

'User → many to many → Role → has many → Permission' 

It looks similar with my case.

But I guess my case is

'User → many to many → Role → belongsTo → Permission'

I am afraid I can not find my case in your comments.

Anyway thanks.

Activity icon

Started a new Conversation Something Like 'hasManyThrough' For HasMany / BelongsToMany ( Many-To-Many ) Grandchild Relation ?

Hi. I have three models.

Alphabet / Category / Videos

Alphabet has hasMany relationship with Categories .

Category has Many-to-Many relationship with Videos.

Alphabet.php

class Alphabet extends Model
{
    public function categories()
    {
        return $this->hasMany(Category::class);
    }
}

Category.php

class Category extends Model
{
    public function alphabet()
    {
        return $this->belongsTo(Alphabet::class);
    }

    public function videos()
    {
        return $this->belongsToMany(Category::class, 'cat_video' );
    }
}

Video.php

class Video extends Model
{
    public function categories()
    {
        return $this->belongsToMany( Category::class, 'cat_video' );
    }
}

What I want to get videos count corresponding to alphabet .

Because it is not a relationship of 'Has Many Through', 'hasManyThrough' does not work .

Is there someone can help me ?

Activity icon

Replied to Pagination In Many-to-Many Relationship.

You great..

Yes.

I should have called 'videos' separate..

And I guess there is no another way with one query.

I just repeat your code for later.


$cat = Cat::where('id', $this->cat_id)->first();

$videos = Video::where('cat_id', $this->cat_id)
	->orderBy(function($query) {
	    if ($this->sortField === 'visits' || $this->sortField === 'recent') {
                $q->orderBy($this->sortField, $sortDirection);
            }
	})
	->paginate();

return view('livewire.cat-show', compact('cat', 'videos'));


Jan
06
1 week ago
Activity icon

Started a new Conversation Pagination In Many-to-Many Relationship.

getting pagination of many to many relationship ??

hi I have two models, Cat ( category) / Video

It is many to many relationship..

One Cat has many to many Videos.

I want to use pagination when getting videos of category.

Models..

class Cat extends Model
{
    public function videos()
    {
        return $this->belongsToMany( Video::class, 'cat_video' );
    }
}

class Video extends Model
{
    public function cats()
    {
        return $this->belongsToMany( Cat::class, 'cat_video' );
    }
}

in controller / Component whatever....


function show(){
    $cat = Cat::where('id', $this->cat_id)
            ->withCount( 'videos');

    if( $this->sortField == 'visits'  ){
        $cat= $cat->with( [ 'videos'=> function( $q ) use($sortDirection) {
            $q->orderBy('visits', $sortDirection);
        }] );
    } elseif( $this->sortField == 'recent' ) {
        $cat= $cat->with( [ 'videos'=> function( $q ) use($sortDirection) {
            $q->orderBy('created_at', $sortDirection);
        }] );
    } 
    
    $cat->first();
    return view('livewire.cat-show', [ 'cat'=>$cat ]);
}

in View


@foreach ($cat->videos as $item)
    <div>{{ $item->title }}</div>
@endforeach


<div>
    {{ $cat->videos()->links() }}
    {{--  error --}} 
    {{ $cat->videos->links() }} 
    {{--  error again --}}

</div>

How can I paginate videos corresponding with category ?

Jan
02
1 week ago
Activity icon

Replied to BelongsToMany Take 1 .

I see the ref.


$category = Cat::find(1);

foreach ($category->videos as $video) {
    //
}

But if i use this code in Controller, not Model I can not use 'Eager Loading' and 'Cache' for 'video' model ..

I wish I can adopt this code on Model.

Activity icon

Replied to BelongsToMany Take 1 .

Is it possible to build relationship with 'hasMany' / 'belongsToManay' pair ?

I don't get it.

Activity icon

Replied to BelongsToMany Take 1 .

I think , I am right.

I am building many-to-many relationship between Category / Video .

Ref: https://laravel.com/docs/8.x/eloquent-relationships#many-to-many

Activity icon

Started a new Conversation BelongsToMany Take 1 .

hi . I have two models and pivot table..

See the relations.

Cat.php

class Cat extends Model
{

    public function videos()
    {
        return $this->belongsToMany( Video::class, 'cat_video' )->withTimestamps();
    }
    
    function videoOne()
    {
        return $this->videos()->orderBy('created_at', 'desc')->take(1);
    }

}

Video.php


class Video extends Model
{
    public function cats()
    {
        return $this->belongsToMany(Cat::class, 'cat_video');
    }

}

I want to get the latest video at each category ( cat. ) .

$cats = Cat::with('videos')->get();

It returns videos ..

$cats = Cat::with('videoOne')->get();

It returns nothing ..

how can I get it ?

Dec
30
2 weeks ago
Activity icon

Started a new Conversation Installing Php 8 On Ubuntu 20 For Laravel

hi.

It could be too much early for new project.

But I want to try..

And maybe there is someone's notes.

How can I install php 8 on Ubuntu 20 for laravel including extensions ?

Dec
28
2 weeks ago
Activity icon

Replied to Php8 With Laravel-valet Does Not Work ( Maybe Yet.. )

Oh... Thank you so much for information.

Thanks.

Dec
27
2 weeks ago
Activity icon

Started a new Conversation Laravel Redis Not Support 'WITHSCORES' Option..

Hi. I am struggling with redis.

I want to insert member with score by ZADD .

And I want retrieve score / member together .

I tried this.

$values = Redis::command('ZADD', ['myset', 15, 'fifthteen']);
$values = Redis::command('ZRANGEBYSCORE', ['myset', '-inf', '+inf', [ 'WITHSCORES' ] ]);
dd( $values );
        	

But it shows only the following .

array:1 [
  0 => "fifthteen"
]

I need value '15' together .

I guess Laravel Redis package does not support redis command options ..

Can someone to give tips?

php 8 / laravel 8.x / redis 6.0.9 used ..

and the extension info is following..

➜  ~ php -i |grep Redis
Redis Support => enabled
Redis Version => 5.3.2
Redis Sentinel Version => 0.1

Activity icon

Awarded Best Reply on Php8 With Laravel-valet Does Not Work ( Maybe Yet.. )

I found solution..

I guess this is better way.

composer global upgrade

valet install

But I am not sure Laravel 7/8 is supporting php-8 yet..

Activity icon

Replied to Php8 With Laravel-valet Does Not Work ( Maybe Yet.. )

I found solution..

I guess this is better way.

composer global upgrade

valet install

But I am not sure Laravel 7/8 is supporting php-8 yet..

Activity icon

Replied to Php8 With Laravel-valet Does Not Work ( Maybe Yet.. )

I guess. it is not good solution..

I'd better use new php version..

Thanks for reply.

Activity icon

Started a new Conversation Php8 With Laravel-valet Does Not Work ( Maybe Yet.. )

By accident I updated my brew ..

And php 8 was installed..

after that , valet does not works..

Test domain does not works..

How can I fix this ?

Does somebody has tips?

Dec
24
3 weeks ago
Activity icon

Started a new Conversation How To Get Stream Of Data From Sub Process ( Nodejs) ?

Hi. I have nodejs program which print json data continually .. something like this..

{
  requestId: '81562.277',
  timestamp: 31248.230696,
  response: {
    opcode: 1,
    mask: true,
    payloadData: '["{\"_event\":\"heartbeat\",\"data\":\"h\"}"]'
  }
}

Actually it is websocket streams from another site.

anyway, I would like to run and watch this node program , and get the stream for long long time..


	$output=null;
        $retval=null;
        $cmd = 'node get_data_program';
        exec( $cmd , $output, $retval);
        print_r($output);

above code is not working for streaming data .

How can I do get streaming data from another sub process?

Dec
11
1 month ago
Activity icon

Replied to How To Get Extra Field Value In Pivot Table Of Many-to-Many Rel.

Ah.. one more question is ok ?

in controller ..


$sites= Site::whereHas('cats', function( $q) use( $cat_id ) {
            $q->where('cat_site.cat_id', $cat_id)
                ->orderBy('cat_site.show_order');
        })->get();

the following is not working as expected

                ->orderBy('cat_site.show_order');

How can I order rows with 'show_order' field in pivot table ?

Thanks.

Activity icon

Replied to How To Get Extra Field Value In Pivot Table Of Many-to-Many Rel.

So nice..

Pushing variable into Model is most fantastic way for me.

Thanks ..

Activity icon

Started a new Conversation How To Get Extra Field Value In Pivot Table Of Many-to-Many Rel.

Models : Cat / Site

Cat.php

class Cat extends Model
{
    function sites(){
        return $this->belongsToMany( Site::class, 'cat_site' )
            ->withPivot(['show_order']);
    }
}

Site.php

class Site extends Model
{
    function cats(){
        return $this->belongsToMany( Cat::class, 'cat_site' )
            ->withPivot(['show_order']);
    }
}

in migration, there is extra 'show_order' column in 'cat_site' table

Schema::create('cat_site', function (Blueprint $table) {
    $table->id();
    $table->unsignedBigInteger('cat_id');
    $table->foreign('cat_id')->references('id')->on('cats')->onDelete('cascade');
    $table->unsignedBigInteger('site_id');
    $table->foreign('site_id')->references('id')->on('sites')->onDelete('cascade');
    $table->integer('show_order');
    $table->timestamps();
    $table->unique(['cat_id', 'site_id']);
});

seeder

$cats = Cat::factory()->count(9)
        ->hasAttached(
            Site::factory()->count(20),
            ['show_order' => mt_rand(0,19)]
        )
        ->create();

/// actually mt_rand function not works as expected...

in controller

$sites= Site::whereHas('cats', function( $q) use( $cat_id ) {
            $q->where('cat_site.cat_id', $cat_id)
                ->orderBy('cat_site.show_order');
        })->get();

foreach( $sites as $site){
    $show_order =  $site->cats->first()->pivot->show_order ;
}

My Question is how to reduce this code shorter ?

    $show_order = $site->cats->first()->pivot->show_order;

Isn't there another way to get extra 'show_order' value in pivot table ?

And I wonder if these way is correct ..

Thanks.

Activity icon

Replied to Laravel 8 Factory Definition With Locale Not Work.

I got it now.


$faker = \Faker\Factory::create('ko_KR');
dd($faker->name);

It works..


$faker = \Faker\Factory::create('ko_KR');
dd($faker->title);

It does not work.

There is no properties as like 'title, paragraph, sentence' in ko_KR / ja_JP locale provider.

Faker package just provides some properties for another locale like 'name , ....' only..

I guess I have to add some more Faker resources for my language..

Really thanks a lot. .

Activity icon

Replied to Laravel 8 Factory Definition With Locale Not Work.

Really thanks for spending your time for my problem..

I modified and run Seeder with following code but no luck again .

But I wonder if ' \Faker\Factory' is correct namespace for this.


public function definition()
    {
        $faker = \Faker\Factory::create('ko_KR');
        static $order = 0;  

        return [
            'show_order'=> $order++ ,
            'title'=> $faker->title, 
            'content'=> $faker->paragraph( 15, true),
            'summary'=> $faker->sentence( 20,true)
        ];
    }
Activity icon

Replied to Laravel 8 Factory Definition With Locale Not Work.

Thanks for comment again .

yes I did without luck again .


php artisan config:clear
php artisan cache:clear 

Can you check My factory file ?

CatFactory.php


<?php

namespace Database\Factories;

use App\Models\Cat;
use Illuminate\Database\Eloquent\Factories\Factory;

class CatFactory extends Factory
{
    protected $model = Cat::class;

    public function definition()
    {
        static $order = 0;  

        return [
            'show_order'=> $order++ ,
            'title'=> $this->faker->title, 
            'content'=> $this->faker->paragraph( 15, true),
            'summary'=> $this->faker->sentence( 20,true),
        ];
    }
}


Activity icon

Replied to Laravel 8 Factory Definition With Locale Not Work.

thanks for reply..

But no luck. it is not working .

IK tried with this too , so I don't have add line in .env file.

in app.php


'faker_locale' => 'ko_KR',

Activity icon

Started a new Conversation Laravel 8 Factory Definition With Locale Not Work.

Hi . how can I use locale ( ko_KR ) in new Laravel 8 factory definition with faker ?

I can not find reference at all ..

Thanks.

Nov
05
2 months ago
Activity icon

Replied to Using 'And Where' In Many To Many Relation.

Actually I tried this .

That is not working for me.

Activity icon

Replied to Using 'And Where' In Many To Many Relation.

for me It should be like this..



$carSelected = [1, 3, 6];

$users = User::when(count($carSelected), function ($query) use ($carSelected) {
     return $query->whereHas('cars', function ($query) use ($carSelected) {
        $query->distinct()->whereIn('cars.id', $carSelected);
    }, '=', count($carSelected));
})->get();

        $query->distinct()->whereIn('cars.id', $carSelected);

I dont understand the reason. But for me without tables name it goes error.

Anyway thank you so much.

Activity icon

Started a new Conversation Using 'And Where' In Many To Many Relation.

Hi .

I have two model which has Many to Many Relationship.

User.php

class User extends Model
{
    function cars(){
        return $this->belongsToMany( Car::class );
    }
}

Car.php

class Car extends Model
{
    function users(){
        return $this->belongsToMany( User::class );
    }
}

I want to get users who used specific cars ;

So I give $car_selected variable ;

    $car_selected = [ 1,3,6 ];

    $users = User::when( count( $car_selected)> 0 , function( $query) use( $car_selected ) {
            $q->whereIn( 'cars.id', $car_selected);
    })->get();

This gives Combination because of 'whereIn' condition .

But What I want is 'whereAnd' something.

I tried this. but no luck.

    $users = User::when( count( $car_selected)> 0 , function( $query) use( $car_selected ) {
        foreach( $car_selected as $xx ){
            $q->where( 'cars.id', $xx);
        }
    })->get();

How can I get 'all users which has all [1,3,6 ] cars '

Sep
04
4 months ago
Activity icon

Started a new Conversation Generate Static Html From Laravel Route.

Hi.

I have trouble from high load on sever.

So I would like to generate html page from laravel .

for example, whenever user access http://domain.com/post/1

all user will see same html page.

So I would like to change some url page to static HTML page.

How can I generate html page from url with parameter. ?

Is there some packages for generating html page ?

Sep
03
4 months ago
Activity icon

Started a new Conversation Indexing On Self Nested Structure For Best Performance?

Hi.

I made Comment with parent_id for self recurring.

in Comment.php


    function children(){
        return $this->hasMany( Comment::class, 'parent_id')->withTrashed();
    }

    function childrenComments(){
        return $this->hasMany( Comment::class, 'parent_id')
                ->with('children')
                ->withTrashed();
    }

    function parent(){
        return $this->belongsTo( Comment::class, 'parent_id')->withTrashed();
    }

in create_comments_table.php



        Schema::create('comments', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('commentable_id');
            $table->string('commentable_type');
            $table->unsignedBigInteger('parent_id')->nullable();
            $table->text('content');
            $table->timestamps();
        });
    }

in controller


function getpost(){

    ...
    $post = Post::with('comments')
            ->with('comments.children')
            ->with('comments.children.children')
            ->with('comments.children.children.children')
            ->with('comments.children.children.children.children')
            ->get();
            
}		

What is the best way for indexing in this case ?

My system is on production.

I guess there is some performance trouble on comments table with self recurring

Does somebody has ideas?

Sep
01
4 months ago
Activity icon

Replied to How To Get One Post With All Nested Tree Structure Comments ..

Thanks for reply.

But your solution does not get infinite nested relationship .

How can I get Infinite Sub hasmany relationship models ?

Activity icon

Started a new Conversation How To Get One Post With All Nested Tree Structure Comments ..

Yeah I guess Somebody have solution for this.

I would like to get 1 post model with all comments.

The comments has children comments.

See this codes.

in Post.php


function comments(){
	return $this->hasMany( Comment::class);

}



in Comment.php


function post(){
	return $this->belongsTo( Post::class );
}

function children(){
	return $this->hasMany( Comment::class, 'parent_id');
}

function parent(){
	return $this->belongsTo( Comment::class, 'parent_id');
}


Yes . Post can hasMany Comments and Comment can be nested with parent_id .

But How can It get Post with all related comments at once ?