Используйте данные строки для вставки в таблицу и обновления текущей таблицы Laravel 5.7. - PullRequest
1 голос
/ 23 января 2020

Я использую данные записей из таблицы, чтобы уменьшить количество записей, которые пользователь сделает, так как они будут сохранены в другой таблице, но после сохранения необходимо обновить статус текущей записи, чтобы он был «Использован»

текущая строка находится в таблице, называемой airfiles, и будет добавлена ​​после добавления суммы продажи в таблицу, называемую tickets

. Вот код схемы airfiles:

public function up()
{
    Schema::create('airfiles', function (Blueprint $table) {
        $table->increments('id');
        $table->string('airl')->nullable();
        $table->string('num')->nullable();
        $table->date('date')->nullable();
        $table->string('pass')->nullable();
        $table->string('route')->nullable();
        $table->string('dot')->nullable();
        $table->string('dor')->nullable();
        $table->string('flynumt')->nullable();
        $table->string('flynumr')->nullable();
        $table->float('fare')->nullable();
        $table->float('tax')->nullable();
        $table->float('total')->nullable();
        $table->float('comm')->nullable();
        $table->float('net')->nullable();
        $table->string('rloc')->nullable();
        $table->string('son')->nullable();
        $table->string('acc')->nullable();
        $table->string('pcc')->nullable();
        $table->tinyInteger('progid')->default('1');
        $table->string('status')->nullable();
        $table->integer('segment')->nullable();
        $table->string('filename')->nullable();
        $table->float('k7')->nullable();
        $table->string('used')->nullable();
        $table->string('transfer')->nullable();
        $table->integer('ticket_id')->unsigned()->nullable();

        $table->rememberToken();
        $table->timestamps();


    });
    Schema::table('airfiles', function (Blueprint $table) {
        $table->foreign('ticket_id')->references('id')->on('tickets')->onDelete('cascade');
    });
}

, а вот код TicketController:

public function store(Request $request, $id)
{
    $this->validate($request,[
        'date'=>'required',
        'tkt_no'=>'required',
        'sector'=>'required',
        'airline'=>'required',
        'supplier'=>'required',
        'fare'=>'required',
        'tax'=>'required',
        'total_tax'=>'required',
        'total_cost'=>'required',
        'k7'=>'required',
        'comm'=>'required',
        'profit'=>'required',
        'sale_price'=>'required',
        'sign'=>'required',
        'pax_name'=>'required',
        'mob'=>'required',
        'amount_arabic'=>'required',
        'amount_english'=>'required',
        'action_type'=>'required',
        'trans_type'=>'required',
        'payment_type'=>'required',

    ]);

    $ticket = new Ticket();
    $ticket->date = $request->get('date');
    $ticket->tkt_no = $request->get('tkt_no');
    $ticket->sector = $request->get('sector');
    $ticket->airline = $request->get('airline');
    $ticket->supplier = $request->get('supplier');
    $ticket->fare = $request->get('fare');
    $ticket->tax = $request->get('tax');
    $ticket->total_tax = $request->get('total_tax');
    $ticket->total_cost = $request->get('total_cost');
    $ticket->k7 = $request->get('k7');
    $ticket->comm = $request->get('comm');
    $ticket->profit = $request->get('profit');

    $ticket->sale_price = $request->get('sale_price');
    $ticket->sign = $request->get('sign');
    $ticket->branch =Auth::user()->branch_id;
    $ticket->pax_name = $request->get('pax_name');
    $ticket->mob = $request->get('mob');
    $ticket->amount_arabic = $request->get('amount_arabic');
    $ticket->amount_english = $request->get('amount_english');
    $ticket->action_type = $request->get('action_type');
    $ticket->trans_type = $request->get('trans_type');
    $ticket->payment_type = $request->get('payment_type');
    $ticket->post_flag = '0';
    $ticket->save();

    Airfile::find($id)->update(['used' => 'Used']);
    session()->flash('success',__('site.added_successfully'));
    return redirect()->route('$tickets.index');
}

вот код закрытия лезвия:

                    <div class="card-content collpase show">
                    <div class="card-body">
                        <form action="{{ route('tickets.store') }}" method="post">

                            {{ csrf_field() }}
                            {{ method_field('post') }}


                            <div class="row">


                                <div class="form-group col-md-2">
                                    <label>@lang('site.son')</label>

                                    @if(Auth::user()->shortsign == '--')
                                        <select class="select2-size-lg form-control border-primary"
                                                style="width: 100%;" name="sign">
                                            @foreach ($users as $user)
                                                <option
                                                    value="{{ $user->shortsign }}">{{ $user->shortsign }}</option>
                                            @endforeach
                                        </select>
                                    @else
                                        <select class="select2-size-lg form-control border-primary"
                                                style="width: 100%;" name="sign" readonly>
                                            <option
                                                value="{{ Auth::user()->shortsign }}">{{ Auth::user()->shortsign }}</option>
                                        </select>
                                    @endif

                                </div>


                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="pax_name">@lang('site.pax_name')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="pax_name" class="form-control"
                                                   name="pax_name"
                                                   value="{{ $airfiles->pass }}" readonly>
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label for="client">@lang('site.client')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="client" class="form-control"
                                                   name="client"
                                                   value="{{ $airfiles->pass }}">
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="mob">@lang('site.mob')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="mob" class="form-control"
                                                   name="mob"
                                                   value="{{ old('mob') }}">
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="form-group col-md-2">
                                    <label>@lang('site.supplier')</label>
                                    <select class="form-control select2 status-type" style="width: 100%;"
                                            name="supplier"
                                            id="supplier">
                                        <option selected value="bsp">BSP</option>
                                        <option value="online">Online</option>
                                    </select>
                                </div>

                                <div class="form-group col-md-2">
                                    <label>@lang('site.action_type')</label>
                                    <select class="form-control select2 status-type" style="width: 100%;"
                                            name="action_type"
                                            id="action_type">
                                        <option selected value="issue">@lang('site.issue')</option>
                                        <option value="reissue">@lang('site.reissue')</option>
                                        <option value="emd">@lang('site.emd')</option>
                                        <option value="refund">@lang('site.refund')</option>
                                        {{--                                            <option value="void_charge">@lang('site.void_charge')</option>--}}
                                    </select>
                                </div>

                                <div class="form-group col-md-2">
                                    <label>@lang('site.trans_type')</label>
                                    <select class="form-control select2 status-type" style="width: 100%;"
                                            name="trans_type"
                                            id="trans_type">
                                        <option selected value="domestic">@lang('site.domestic')</option>
                                        <option value="international">@lang('site.international')</option>
                                    </select>
                                </div>

                                <div class="form-group col-md-2">
                                    <label>@lang('site.payment_type')</label>
                                    <select class="form-control select2 status-type" style="width: 100%;"
                                            name="payment_type"
                                            id="payment_type">
                                        <option selected value="cash">@lang('site.cash')</option>
                                        <option value="credit">@lang('site.credit')</option>
                                        <option value="advance">@lang('site.advance')</option>
                                        <option value="pending">@lang('site.pending')</option>
                                    </select>
                                </div>

                                <div class="form-group col-md-2">
                                    <label>@lang('site.airline')</label>
                                    <select class="form-control select2 status-type" style="width: 100%;"
                                            name="airline"
                                            id="airline">
                                        @foreach ($airlines as $airline)
                                            <option value="{{ $airline->code }}">{{ $airline->code }}</option>
                                        @endforeach
                                    </select>
                                </div>

                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="sale_price">@lang('site.sale_price')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="sale_price" class="form-control"
                                                   name="sale_price" placeholder="0"
                                                   onkeypress="return isNumberKey(event)"
                                                   {{--                                                       onblur="findTotal()"--}}
                                                   onkeyup="main ();eng_main();findTotal()"
                                                   value=" {{ old('sale_price') }}">
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="tkt_no">@lang('site.tkt_no')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="tkt_no" class="form-control"
                                                   name="tkt_no" onkeypress="return isNumberKey(event)"

                                                   value="{{ $airfiles->num }}" readonly>
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="rloc">@lang('site.rloc')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="rloc" class="form-control"
                                                   name="rloc"
                                                   value="{{ $airfiles->rloc }}" readonly>
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="col-md-4">
                                    <div class="form-group">
                                        <label for="sector">@lang('site.sector')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="sector" class="form-control"
                                                   name="sector" placeholder="@lang('site.like') : HAS/JED JED/MAA"
                                                   value="{{ $airfiles->route }}" readonly>
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="fare">@lang('site.fare')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="fare" class="form-control "
                                                   onblur="findTotal()"
                                                   name="fare" placeholder="0"
                                                   {{--                                                       onkeyup="main ()"--}}
                                                   value="{{ $airfiles->fare }}" readonly>
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="tax">@lang('site.tax')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="tax" class="form-control"
                                                   name="tax" placeholder="0"
                                                   onkeypress="return isNumberKey(event)"
                                                   onblur="findTotal()"
                                                   {{--                                                       onkeyup="return sum(event)"--}}
                                                   value="{{ $airfiles->tax }}" readonly>
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="k7">@lang('site.k7')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="k7" class="form-control"
                                                   name="k7" placeholder="0"
                                                   onkeypress="return isNumberKey(event)"
                                                   onblur="findTotal()"
                                                   {{--                                                       onkeyup="return sum(event)"--}}
                                                   value="{{ $airfiles->k7 }}" readonly>
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="comm">@lang('site.comm')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="comm" class="form-control"
                                                   name="comm" placeholder="0"
                                                   onkeypress="return isNumberKey(event)"
                                                   onblur="findTotal()"
                                                   {{--                                                       onkeyup="return sum(event)"--}}
                                                   value="{{ $airfiles->comm }}" readonly>
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="profit">@lang('site.profit')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="number" id="profit" class="form-control"
                                                   name="profit" placeholder="0"
                                                   onkeypress="return isNumberKey(event)"
                                                   onblur="findTotal()"
                                                   {{--                                                       onkeyup="return sum(event)"--}}
                                                   value="{{ number_format(old('profit'), 2) }}" readonly>
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="total_tax">@lang('site.total_tax')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="total_tax" class="form-control"
                                                   name="total_tax" placeholder="0"
                                                   onkeypress="return isNumberKey(event)"
                                                   onkeyup="return sum(event)"
                                                   value="{{ old('total_tax') }}" readonly>
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label for="total_cost">@lang('site.total_cost')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="total_cost" class="form-control"
                                                   name="total_cost" placeholder="0"
                                                   onkeypress="return isNumberKey(event)"
                                                   onkeyup="return sum(event)"
                                                   value="{{ old('total_cost') }}" readonly>
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="col-md-4">
                                    <label for="date">@lang('site.date')</label>
                                    <div class="input-group">
                                        <input id="date" name="date" class="form-control datepicker" type="date"
                                               value="{{ $airfiles->date }}" readonly>
                                    </div>
                                </div>

                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="amount_arabic">@lang('site.amount_arabic')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="amount_arabic" class="form-control"
                                                   name="amount_arabic"
                                                   onkeypress="return isNumberKey(event)"
                                                   onkeyup="return sum(event)"
                                                   value=" {{ old('amount_arabic') }}" readonly>
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="amount_english">@lang('site.amount_english')</label>
                                        <div class="position-relative has-icon-left">
                                            <input type="text" id="amount_english" class="form-control"
                                                   name="amount_english"
                                                   onkeypress="return isNumberKey(event)"
                                                   onkeyup="return sum(event)"
                                                   value=" {{ old('amount_english') }}" readonly>
                                            <div class="form-control-position">
                                                <i class="la la-keyboard-o"></i>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                            </div>


                            <div class="form-actions right">
                                <button id="slide-toast" type="submit"
                                        class="btn btn-outline-warning btn-min-width box-shadow-2 mr-1 mb-1"><i
                                        class="la la-check-square-o"></i> @lang('site.close')</button>
                            </div>

                        </form><!-- end of form -->


                    </div><!-- end of box -->
                </div>

вот код маршрута:

    //airfile routes
Route::resource('airfiles', 'AirfileController')->except(['show']);
//ticket routes
Route::resource('tickets', 'TicketController')->except(['show']);

ошибка, которую я получил:

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_RECOVERABLE_ERROR) Слишком мало аргументов для функции App \ Http \ Controllers \ TicketController :: store (), 1 пройдено и ожидается ровно 2

кто-нибудь может помочь?

1 Ответ

0 голосов
/ 23 января 2020

Это потому, что этот метод ожидает идентификатор и, возможно, вы не передали идентификатор из маршрута этому методу. Вы можете передать id для маршрута следующим образом:

{{ route('routeName', ['id' => 1]) }}

И сделать свой маршрут следующим образом:

Route::get('appName/{id}', ControllerName@store)->name('routeName');
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...