第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Laravel 在字段驗(yàn)證后插入記錄

Laravel 在字段驗(yàn)證后插入記錄

PHP
HUWWW 2022-08-05 09:56:08
我正在嘗試 Laravel 5.6 請(qǐng)求驗(yàn)證。我面臨幾個(gè)問(wèn)題1.無(wú)法在視圖中查看驗(yàn)證消息。2.添加驗(yàn)證碼后數(shù)據(jù)不插入數(shù)據(jù)庫(kù)。(在添加驗(yàn)證之前,它是工作)3 如何驗(yàn)證下拉列表狀態(tài)?(應(yīng)選擇“活動(dòng)”/“非活動(dòng)”)名稱(chēng).刀片.php<form action="{{url('./designation/store')}}" method="POST">      <div class="form-row">        <div class="form-group col-md-7">          <label for="inputDesignation">Designation</label>          <input type="text" name="designation" class="form-control" id="inputDesignation">        </div>        <div class="form-group col-md-5">          <label for="inputStatus_Designation">Status</label>          <select name="status" id="inputStatus_Designation" class="form-control">            <option selected>Select Status</option>            <option >Active</option>            <option >Inactive</option>          </select>        </div>      </div>      <button type="submit" class="btn btn-success" id="btn_add_designation">Add</button>      {{ csrf_field() }}  </form>指定控制器.phppublic function store(Request $request){    //Validation the Data    $validatedData = $request->validate([        'designation_type' => ['required','max:255'],        'status' => ['required'],    ],    [        'designation_type.required' => 'Designation is required',        'designation_type.max' => 'Designation should not be greater than 255 characters.',    ]);    //Data Insert into database   $data =[       'designation_type'=>$request->input('designation'),       'status'=>$request->input('status')   ];   DB::table('designation')->insert($data);   return redirect('/designation');}請(qǐng)幫我解決這個(gè)問(wèn)題!
查看完整描述

3 回答

?
慕田峪4524236

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個(gè)贊

   public function store(Request $request)

        {

            $this->validate($request,[

                'name' => 'required'

            ]);


            $category = new Category();

            $category->name = $request->name;

            $category->slug = str_slug($request->name);

            $category->save();

            Toastr::success('Category Successfully Saved','Success');

            return redirect()->route('admin.category.index');

        }



// blade 


<form method="POST" action="{{ route('admin.category.store') }}">

   @csrf

   <div class="form-group form-float">

     <div class="form-line">

     <input value="{{ old('name') }}" name="name" type="text" id="category_name" class="form-control">

     <label class="form-label">{{ __('Name') }}</label>

       </div>

        </div>

          <br>


         <a href="{{ route('admin.category.index') }}"  class="btn btn-danger m-t-15 waves-effect">{{ __('BACK') }}</a>

          <button type="submit" class="btn btn-primary m-t-15 waves-effect">{{ __('SUBMIT') }}</button>

</form>


查看完整回答
反對(duì) 回復(fù) 2022-08-05
?
烙印99

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超13個(gè)贊

嘗試以下代碼


public function store(Request $request)

{

    //Validation the Data


    $validatedData = $request->validate([

        'designation_type' => ['required','max:255'],

        'status' => ['required'],

    ],

    [

        'designation_type.required' => 'Designation is required',

        'designation_type.max' => 'Designation should not be greater than 255 characters.',

    ]);



    if($validatedData->fails()) {

      return Redirect::back()->withErrors($validatedData);

    }



    //Data Insert into database

   $data =[

       'designation_type'=>$request->input('designation'),

       'status'=>$request->input('status')

   ];

   DB::table('designation')->insert($data);


   return redirect('/designation');

}





<form action="{{url('./designation/store')}}" method="POST">

      <div class="form-row">

        <div class="form-group col-md-7">

          <label for="inputDesignation">Designation</label>

          <input type="text" name="designation" class="form-control" id="inputDesignation">

          @if($errors->has('designation'))

            <div class="error">{{ $errors->first('designation') }}</div>

        @endif

        </div>

        <div class="form-group col-md-5">

          <label for="inputStatus_Designation">Status</label>

          <select name="status" id="inputStatus_Designation" class="form-control">

            <option selected>Select Status</option>

            <option >Active</option>

            <option >Inactive</option>

          </select>

          @if($errors->has('status'))

            <div class="error">{{ $errors->first('status') }}</div>

        @endif

        </div>

      </div>


      <button type="submit" class="btn btn-success" id="btn_add_designation">Add</button>

      {{ csrf_field() }}

  </form>


查看完整回答
反對(duì) 回復(fù) 2022-08-05
?
侃侃無(wú)極

TA貢獻(xiàn)2051條經(jīng)驗(yàn) 獲得超10個(gè)贊

在參考此 https://laravel.com/docs/5.6/validation#named-error-bags 之后,我對(duì)代碼進(jìn)行了一些更改,這有助于解決錯(cuò)誤。


在指定.刀片中.php已添加


 @if ($errors->any())

<div class="alert alert-danger">

    <ul>

        @foreach ($errors->all() as $error)

            <h6>{{ $error }}</h6>

        @endforeach

    </ul>

</div>

@endif

在指定控制器中.php


用于狀態(tài)下拉驗(yàn)證。


'status' => 'required|not_in:0',

用于數(shù)據(jù)插入數(shù)據(jù)庫(kù)部件


DB::table('designation')->insert($validatedData);

完整代碼


名稱(chēng).刀片.php


<div class="row">

  <div class="col-md-2"></div>

    <div class="col-md-8">

      @if ($errors->any())

        <div class="alert alert-danger">

        <ul>

        @foreach ($errors->all() as $error)

            <h6>{{ $error }}</h6>

        @endforeach

    </ul>

</div>

@endif

</div>

 <div class="col-md-2"></div>

 </div>

 <div class="row">

<div class="col-md-4"></div>

<div class="col-md-4">

  <form action="{{url('./designation/store')}}" method="POST">

      <div class="form-row">

        <div class="form-group col-md-7">

          <label for="inputDesignation">Designation</label>

          <input type="text" name="designation_type" class="form-control" id="inputDesignation">

        </div>

        <div class="form-group col-md-5">

          <label for="inputStatus_Designation">Status</label>

          <select name="status" id="inputStatus_Designation" class="form-control">

            <option selected value="">Select Status</option>

            <option value="Active">Active</option>

            <option value="Inactive">Inactive</option>

          </select>

        </div>

      </div>

      {{-- <button type="submit" class="btn btn-primary">Sign in</button> --}}

      <button type="submit" class="btn btn-success" id="btn_add_designation">Add</button>

      {{ csrf_field() }}



  </form>

</div>

 <div class="col-md-4"></div>

</div>

指定控制器.php


public function store(Request $request)

{

    $validatedData = $request->validate([

        'designation_type' => 'required|max:255',

        'status' => 'required|not_in:0',

    ],

    [

        'designation_type.required' => 'Designation is required !!',

        'designation_type.max' => 'Designation should not be greater than 255 characters.',

        'status.required' => 'Status is required !!'

    ]);


    DB::table('designation')->insert($validatedData);

    return redirect('/designation');

}

謝謝你們花寶貴的時(shí)間幫助我...!!!


查看完整回答
反對(duì) 回復(fù) 2022-08-05
  • 3 回答
  • 0 關(guān)注
  • 125 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)