Ich habe eine Mysql Tabellerekursive Funktion nicht alle Kinder in Laravel Rückkehr 5
Das ist mein Modell ist
namespace App;
use Illuminate\Database\Eloquent\Model;
class Categories extends Model {
protected $table = 'category';
protected $fillable = ['category_name', 'parent_id', 'category_level', 'last_level', 'description', 'category_image'];
protected $guarded = ['id'];
public function parent()
{
return $this->belongsTo('App\Categories', 'parent_id');
}
public function children() {
return $this->hasMany('App\Categories','parent_id');
}
}
und dies ist mein Controller-Methode
public function create() {
$parentCategory = Categories::all();
return view('admin.add_category')->with('parentCategory', $parentCategory);
}
Ich möchte dieses Ergebnis erhalten
Wie ist es möglich?
EDIT
und das ist meine Ansicht:
<select name="category_id" id="p_category_id" class="form-control">
<option selected="selected" value="">Select Cateory</option>
<option selected="" value="">Category</option>
@foreach ($parentCategory as $category)
@foreach ($category->children as $child)
<option value="{{ $category->id }}" placeholder="choose parent category">{{ $child->category_name }}</option>
@endforeach
@endforeach
</select>
ich dieses Ergebnis wollen:
Category
Bangladesg
----Dhaka
---------Mirpur
---------------Senpara
---------Mohammadpur
----Rangpur
@Epodax Sahen, dass nicht in der Kritik , werde ich mir ansehen – Draken