I found this function in Internet and it works.
In my App
public function childs(){
return $this->hasMany('App\Account','p_id');
}
In my route:
Route::get('tests', function(){
return App\Account::with('childs')
->where('p_id',0)
->get();
});
So if you have in the dabase a raw with p_id = 0 and id = 1 it return a category and if you have a raw with p_id = 1 and id = 2 that mean that the child of the categorie with id = 1.
Another example::
If you have a raw with p_id = 6 and id = 16 that mean that the child of the category with id = 6
Please who can explain to mean why exactly it work like that ?