我正在使用laravel 5.6,并且正在开发自动分类网络应用程序。在我的应用程序中,我有3种不同的车辆类别,例如小汽车,厢式货车,卡车,并且我有刀片文件来选择这三种不同的车辆类型。当我选择这辆车时,我的网址显示如下,
http://localhost:8000/post-ad/Truck/8 <- this is category id
http://localhost:8000/post-ad/van/7
http://localhost:8000/post-ad/Car/5
现在,当我单击以上车辆类别页面中的一个重定向到show.blade.php文件时,所以,现在我需要3种不同的表格来向每辆车提交数据,这是我的车辆表格,即汽车表格
<form method="post" action="{{url('form')}}" enctype="multipart/form-data">
{{csrf_field()}}
<input type="hidden" id="cid" name="cid" value="{{ $catagories->id }}" />
<div class="form-group">
<label for="exampleFormControlSelect1">District</label>
<select class="form-control" id="exampleFormControlSelect1" name="district">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Town</label>
<select class="form-control" id="exampleFormControlSelect1" name="town">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Brand</label>
<select class="form-control" id="exampleFormControlSelect1" name="brand">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Model</label>
<select class="form-control" id="exampleFormControlSelect1" name="model">
</select>
</div>
</form>
范式
<form method="post" action="{{url('form')}}" enctype="multipart/form-data">
{{csrf_field()}}
<input type="hidden" id="cid" name="cid" value="{{ $catagories->id }}" />
<div class="form-group">
<label for="exampleFormControlSelect1">District</label>
<select class="form-control" id="exampleFormControlSelect1" name="district">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Town</label>
<select class="form-control" id="exampleFormControlSelect1" name="town">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Brand</label>
<select class="form-control" id="exampleFormControlSelect1" name="brand">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Model</label>
<select class="form-control" id="exampleFormControlSelect1" name="model">
</select>
</div>
</form>
卡车表格
<form method="post" action="{{url('form')}}" enctype="multipart/form-data">
{{csrf_field()}}
<input type="hidden" id="cid" name="cid" value="{{ $catagories->id }}" />
<div class="form-group">
<label for="exampleFormControlSelect1">District</label>
<select class="form-control" id="exampleFormControlSelect1" name="district">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Town</label>
<select class="form-control" id="exampleFormControlSelect1" name="town">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Brand</label>
<select class="form-control" id="exampleFormControlSelect1" name="brand">
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Model</label>
<select class="form-control" id="exampleFormControlSelect1" name="model">
</select>
</div>
</form>
当某些用户单击一个刀片文件上的每个车辆链接时,我需要显示每个表格。我该怎么办?
答案 0 :(得分:2)
您可以在路线中添加名称,例如:
Route::group(['prefix' => 'post-ad'], function () {
Route::get('Truck/{id}', 'TruckController@fetch')->name('track');
Route::get('Van/{id}', 'VanController@fetch')->name('van');
Route::get('Car/{id}', 'CarController@fetch')->name('car');
})
将您的表单放置到另一个文件中,例如:
truck-form.blade.php
van-form.blade.php
car-form.blade.php
您认为:
@if(request()->route()->getName() = 'track')
@include('truck-form')
@elseif(request()->route()->getName() = 'van')
@include('van-form')
@elseif
@include('van-form')
@endif