存储功能在Laravel中不起作用

时间:2018-07-29 15:40:54

标签: laravel-5 laravel-blade

有人可以帮我解决此问题吗?当我单击提交时,它不起作用! 我认为问题出在表单的action =“”。路线正确吗? 如果这是为什么它不起作用?

这些是我的路线:

Route::middleware(['auth'])->group(function () {

    Route::get('/', 'HomeController@index')->name('home');
    Route::resource('stocks', 'StockController');    
    Route::get('/stocks/{stock_tag}/doctor','DoctorController@index')->name('stock.doctor');
    Route::get('/stocks/{stock_tag}/doctor/create','DoctorController@create')->name('stock.doctor.create'); 
    Route::post('/stocks/{stock_tag}/doctor/store','DoctorController@store')->name('stock.doctor.store');    
});

我在DoctorController中的存储功能

public function store(Request $request,$stock_tag)
{
    //
    $stock = Stock::find($stock_tag); 
    if(Auth::check()){
            $doctor = Doctor::create([
                'date_of_visit' => $request->input('date_of_visit'),
                'doc_name' => $request->input('doc_name'),
                'remarks' => $request->input('remarks'),
                'description' => $request->input('description'),                                 
                'tag' => $stock->tag_no
            ]);               

            if($doctor){
                 return redirect()->route('stocks.doctor.index', ['doctor'=> $doctor->tag])             
                ->with('success' , 'Visit created successfully');
            }                
    }        
    return back()->withInput()->with('errors', 'Error creating new Visit');
}

这是我的观点:

 <form method="post" action="{{ route('stock.doctor.store',$stock->tag_no) }}" enctype="multipart/form-data">       
    {{ csrf_field() }}

    <div class="form-inline">
        <label for="date">Date of Visit</label>
        <input type="date" name="date_of_visit" max="2030-12-31">                     
    </div> 

    <div class="form-inline">
      <label for="doc_name">Doctor Name: </label>
      <input type="text" name="doc_name">          
    </div>

    <div class="form-inline">
      <label for="remarks">Remarks </label>
      <input type="text" name="remarks">          
    </div>

    <div class="form-inline">
      <label for="description">Medication and Execution </label>
      <input type="text" name="description">          
    </div>       
  </form>

  <div class="form-group">
    <input type="submit" class="btn btn-primary"
        value="Submit"/>      
</div>
</div>

1 个答案:

答案 0 :(得分:0)

只需将按钮放在XD表单内!