2017-02-18 3 views
0

Ich habe ein Problem, Wert aus Dropdown mit Laravel zu erhalten Bitte sagen Sie mir, ich bin neu im Laravel.So holen Sie den dynamischen Dropdown-Wert mit Laravel 5.4.6

Blade-Code:

<form method="POST" action="{{url('/add_sub_cat')}}" enctype="multipart/form-data"> 
    <input type="hidden" name="_token" value="{{ csrf_token() }}"> 
    <div class="form-group"> 
    <label for="cat">Category</label> 
     <select class="form-control"> 
     @foreach($categories as $cat) 
     <option id="categoryId" value="{{$cat->id}}" selected="selected">{{ $cat->category }}</option> 
     @endforeach 
     </select> 
    </div> 
    <div class="form-group"> 
     <label for="sub">Sub Category</label> 
     <input type="text" class="form-control" name="subcategory" id="" {{ old('subcategory') }}> 
    </div> 

    <div class="form-group"> 
     <button type="submit" class="btn btn-default">Create</button> 
     <a href="{{url('/subcategory')}}" class="btn btn-default">Cancel</a> 
    </div> 
</form> 
+0

Sie haben es in Controller geschrieben ?? – Sona

+0

Ja, ich habe geschrieben es – Savvy

+0

meine Antwort überprüfen einmal – Sona

Antwort

0

Hallo Du den Namen Attribut in <select name="anythingYouWant"> fehlt.

<form method="POST" action="{{url('/add_sub_cat')}}" enctype="multipart/form-data"> 
<input type="hidden" name="_token" value="{{ csrf_token() }}"> 
<div class="form-group"> 
<label for="cat">Category</label> 
    <select class="form-control"> 
    @foreach($categories as $cat) 
    <option id="categoryId" value="{{$cat->id}}" selected="selected">{{ $cat->category }}</option> 
    @endforeach 
    </select> 
</div> 
<div class="form-group"> 
    <label for="sub">Sub Category</label> 
    <input type="text" class="form-control" name="subcategory" id="" {{ old('subcategory') }}> 
</div> 

<div class="form-group"> 
    <button type="submit" class="btn btn-default">Create</button> 
    <a href="{{url('/subcategory')}}" class="btn btn-default">Cancel</a> 
</div> 

+0

es bekam, @AdnanMumtaz, vielen Dank Sie mein Tag :) – Savvy

1
Try this. 

1.In controller get all the categories list like below. 

$categories=DB::table('categories')->get();//use table or model name ur wish. 

step 2:pass those values to view page like this: 

    return view('viewpagename',compact('categories')); 

Controlle part is done 

Now go to view blade.php page and then continue like this: 



<select id="category" name="category" class="form-control"> 
     <option value="">Select Category</option> 
     @foreach($categories as $key => $value) 
     <option value="{{$value->parent_id}}">{{$value->cat_name}}</option> 
     @endforeach 
</select> 
+0

vielen Dank für die Unterstützung – Savvy

+0

gespeichert haben es gemacht wird .. @ MuhammadAmir – Sona

+0

ja getan, dank @Sona – Savvy

1

Bitte geben Sie einen Namen für Ihre Select HTML-Tag:

Für Ex:

<select class="form-control" name="your-tag-name"> 
     @foreach($categories as $cat) 
     <option id="categoryId" value="{{$cat->id}}" selected="selected">{{ $cat->category }}</option> 
     @endforeach 
     </select> 

Name-Attribut in Ihrem Code fehlt.

+0

danke @Muthu, ich habe es geschafft :) – Savvy

Verwandte Themen