jeudi 21 janvier 2016

Populate dropdown based on previous selection

am trying to implement into my app ability to populate a select drop base on a previous selection. Its a category and subcategory feature. I can get this to work. Any help will be appreciated. My Controller:

public function create()
{
    $categories = Category::whereNull('parent_id')->with('children')->get();

    $user = '';

    if (Auth::check()) {
        $user = User::findById(auth()->user()->id);
    }

    return view('frontend.users.new-ad', compact('categories', 'user'));
}

Category Model

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

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

My Routes.php

Route::get('create-ad', 'AdsController@create');



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire