簡體   English   中英

如何在Laravel 5.6的一個刀片文件中使用不同的形式

[英]how to use different forms in one blade file in laravel 5.6

我正在使用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種不同的表單來向每個車輛提交數據,這是我的車輛表單,即car表單

<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>

當某些用戶單擊一個刀片文件上的每個車輛鏈接時,我需要顯示每個表格。 我怎樣才能做到這一點?

您可以在路線中添加名稱,例如:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM