mercredi 18 mars 2020

Dynamic Dependent Drop Down List In Laravel

I have 3 different tables in database named productdetails,categories & subcategorydetails and likewise I have 3 different Controllers ProductdetailContoller,CategoryController & SubcategorydetailController respectively. Currently, i'm working on SubcategorydetailContoller's 'view' which is subcategory.blade.php

`

            @csrf
            <div class="form-group">

              <select name="productid">


                <option value="select product">
                @foreach ($productdetail as $row)
                  <option value="">
                    
                  </option>
                  @endforeach
                  </option>
              </select>

              <select name="categoryid">


                <option value="select category">
                @foreach ($category as $row)
                  <option value="">
                    

                  </option>
                  @endforeach
                  </option>
              </select>

              <input type="text" name="subcategory"/>

              <input type="submit" value="add category"/>
            </div>
          </form>
        </div>`

Now i want to make dynamically dependent drop-down lists but before working for this, I couldn't be able to show the data of second table into second drop-down list.

Here's what i'm doing in my controller:

namespace App\Http\Controllers;
use App\productdetail;
use App\category;
use App\subcategorydetail;
use Illuminate\Http\Request;

class SubcategorydetailController extends Controller
{

    public function index()
    {  

       $productdetails=productdetail::all();
        return view('subcategory')->with('productdetail',$productdetails);

        //i wrote this in another class but i still didn't get the desired output
        $category=category::all();
        return view('subcategory')->with('category', $category);

    }



    public function create()
    {

    }


    public function store(Request $request)
    {
        $data=new subcategorydetail();
        $data->SubCatType=$request->subcategory;
        $data->CategoryID=$request->categoryid;
        $data->save();
        return dd($data);
        //return view('subcategory');
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire