Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel parent child same table

    public function parent()
    {
        return $this->belongsTo('AppCourseModule','parent_id')->where('parent_id',0);
    }

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

laravel parent child relationship in same table

namespace AppModels;

use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;

class Test extends Model
{
    use HasFactory;

    protected $parentColumn = 'parent_id';

    public function parent()
    {
        return $this->belongsTo(Test::class,$this->parentColumn);
    }

    public function children()
    {
        return $this->hasMany(Test::class, $this->parentColumn);
    }

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

}
Comment

PREVIOUS NEXT
Code Example
Php :: cors error angular php 
Php :: copy folder contect to anthor folder php 
Php :: header php location 
Php :: php read from mariadb 
Php :: laravel 8 register with email verification 
Php :: 413 error laravel 
Php :: mysql get number of rows php 
Php :: select option in laravel 
Php :: Laravel eloquent permanent soft delete 
Php :: laravel password require one letter and one number 
Php :: laravel model wherein update 
Php :: laravel signed Route custom domain 
Php :: today date to ago for the date in php 
Php :: composer create project 
Php :: jquery code to trigger php function 
Php :: @lang laravel blade 
Php :: ziparchive php example 
Php :: carbon compare same date 
Php :: why we use .htaccess file in php 
Php :: fillable property to allow mass assignment 
Php :: Add Text Before the Product Title 
Php :: softDelete laravel8 
Php :: datatable filters 
Php :: jquery greater than or equal to 
Php :: laravel using username instead of email 
Php :: laravel vue browser cache auto clear 
Php :: php image rotate upload 
Php :: php url variables 
Php :: html in php function 
Php :: phpmyadmin drop database 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =