【问题标题】:data is not submitting into db laravel:5.8数据未提交到 db laravel:5.8
【发布时间】:2019-07-12 15:09:39
【问题描述】:

您好,我试图将数据保存在 db 中,但它没有保存 ant 说 404|not 找到了

控制器:

   DB::table('forms')->insert([
        'patient_insurance' => $request->patient_insurance,
        'patient_insurance_id' => $request->patient_insurance_id,
        'patient_reason' => $request->patient_reason,
        'patient_new' => $request->patient_new,
        'patient_message' => $request->patient_message,

    ]);
    return back();

路线:

  Route::resource('form', 'FormController');

刀片:

  <form method="post" action="{{ route('form.store')}}">

型号:

   protected $guarded = [];

   protected $table = "forms";

   protected $fillable= 
   ['patient_name','patient_insurance','patient_insurance_id', 
   'patient_reason', 'patient_new', 'patient_message'];

任何人都可以告诉我这个问题

【问题讨论】:

标签: laravel eloquent laravel-5.8


【解决方案1】:

你不应该在 FormController 类的 store 函数中插入数据吗?

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Patient;
class FormController extends Controller{
    public function store(Request $request){
        $patient = new Patient;
        $patient->patient_insurance = $request->input('patient_insurance');
        $patient->patient_insurance_id = $request->input('patient_insurance_id');
        $patient->patient_reason = $request->input('patient_reason');
        $patient->patient_new = $request->$request->input('patient_new);
        $patient->patient_message = $request->input('patient_message');
        $patient->save();
        return back();
    }
}

【讨论】:

  • 嗨,我刚刚在我的控制器中添加了这两行(使用 App\Http\Requests;使用 App\Http\Controllers\Controller;)并且数据开始提交,,你能解释一下什么是这是什么意思,他们的目的是什么?
  • 如果要将数据保存到db中,需要在store函数中进行。在之前的 laravel 版本中是这样做的,请阅读laravel.com/docs/5.8/controllers#basic-controllers
猜你喜欢
  • 2019-11-18
  • 2019-05-30
  • 2019-05-29
  • 2020-03-01
  • 2016-07-23
  • 2019-01-25
  • 1970-01-01
  • 1970-01-01
  • 2019-06-18
相关资源
最近更新 更多