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 :: how to check user already exists in php 
Php :: php strict mode 
Php :: php string nach zeichen zerlegen 
Php :: a facade root has not been set laravel 7 
Php :: connect another database in wordpress 
Php :: laravel throttle 
Php :: how to get shop page url in wordpress 
Php :: laravel: get last id 
Php :: wp_query post by category taxonomy 
Php :: Day of Week Using carbon library 
Php :: mac brew install php redis 
Php :: laravel migration remove nullable 
Php :: form validation for file type in codeigniter 
Php :: Best debugging tools for php 
Php :: array pop php 
Php :: Make a Woo required field not required 
Php :: file upload permission in php 
Php :: laravel array cast 
Php :: how to remove array index from json in php 
Php :: json encode decode 
Php :: post php 
Php :: run schedule laravel 
Php :: laravel route contains particular segment 
Php :: yesterday php 
Php :: calculate percentage of amount in php 
Php :: laravel route param blade 
Php :: check date PHP 
Php :: date format with t and z php 
Php :: Entity of type "DoctrineCommonCollectionsArrayCollection" passed to the choice field must be managed. Maybe you forget to persist it in the entity manager? 
Php :: put woocommerce orders on pending payment automatically 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =