jQuery验证插件在Laravel中不起作用

时间:2019-12-06 12:28:46

标签: jquery laravel

我在laravel项目中使用了一个jQuery验证插件。我以一种形式添加了验证。对于此表单,我们可以从2条不同的路线中查找同一表单。如果我正在通过POST方法,则jquery验证将起作用。如果我正在通过GET方法,则它将无法工作。

我的路线

Route::post('/searchparentdetails','StudentController@search')->middleware('permission:Add-Student');  
// from this route it will working 


Route::get('addstudent/{id}','ParentController@addstudent')->name('addstudent');

//from this route it will not working 

这是我的控制器

public function search(Request $request){

    $this->validate($request,[
        'parentmobile' => 'required'
    ]);
    $ids = Academic::select('id')->active()->first();

    $mob = $request->input('parentmobile');

    $parent = DB::table('parent_names')->where('mobile',$mob)->where('academic_id',$ids->id)->count();

    if($parent > 0)
    {
        $course = Course::all();
        $parentdetails = DB::table('parent_names')->where('mobile',$mob)
         ->where('academic_id',$ids->id)->first();
        return view('students.create',compact('parentdetails','course'));

    }

}


public function addstudent($id)
{
    $course = Course::all();
    $parentdetails = ParentName::find($id);
    return view('students.create',compact('parentdetails','course'));

}

表格

<form method="post" id="studentform"  action="{{ url('storestudent') }}">
<input type="hidden" name="parentid" value="<?php echo $parentdetails->id ?>" >
  {{ csrf_field() }}


  <div class="row">
    <div class="col-lg-12">
      <p class="topheading">School Details</p>
    </div>
      <div class="col-lg-6 col-md-6 col-sm-12">
          <div class="form-group">
            <div class="row">
              <div class="col-lg-4">
                   Admission to class
              </div>
              <div class="col-lg-8">
                 <select class="form-control" name="course" id="course_name">
                     <option disabled selected>Select</option>
                     @foreach($course as $cou)
                  <option value="{{$cou->id}}">{{$cou->course_name}}</option>
                     @endforeach
                 </select>
              </div>
            </div>

           </div>
         </div>

   <input type="submit" class="btn btn-success" value="Add">
</div>

验证文件

   $('#studentform').validate({
       rules: {
            course: {
                required:true,

            },
    });

0 个答案:

没有答案