But my point of view all category which show and click any category after open related to subcategory.. This is my view file of model code
<!-- Button to Open the Modal -->
<div class="form-group col-md-8">
<button type="button" class="form-control" data-toggle="modal" data-target="#myModal">
Category </button>
<!-- The Modal -->
<div class="modal" id="myModal">
<div class="modal-dialog modal-lg" >
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Category</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div class="row">
<div class="col-md-4" >
<a href="#" name="category" id="category" >
@foreach($categories as $category)
<option value=""></option>
@endforeach
</a>
</div>
<div class="col-md-4 ">
<a href="#" name="subcategory" id="subcategory" >
@foreach($subcategories as $subcategory)
<option value=""></option>
@endforeach
</a>
</div>
<div class="col-md-4">
hhh
</div>
</div>
</div>
</div>
</div>
</div>
</div>
This is my controller
public function create()
{
$categories = Category::all();
$subcategories = Subcategory::all();
return view('post.create', compact('categories', 'subcategories'));
}
This is route:
Route::get('/post/create', 'PostController@create')->name('post.create');
I created api but don't know how to use. This is my API
public function getSubcategory(Request $request)
{
$id = $request->id;
$subcategories = Subcategory::where('category_id',$id)
->select('subcategory','id')
->pluck('subcategory', 'id');
return json_encode($subcategories);
}
API route
Route::get('api/getSubcategory/{id}', 'PostController@getSubcategory');
How can I do this runtime in model change subcategory related to category please help me
I am newbie in this...
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2SbIlIQ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire