当我提交表单时,它不会将信息保存在数据库中,我使用 laravel 8
when I submit my form it doesn't save the information in the database, I use laravel 8
当我提交表单时,它不会将信息保存在数据库中,而只是刷新页面,如果我在控制器中删除与我的请求的关系,记录将保存在数据库中,但因为我可以'使用$request,数据null到达
控制器
* @param \App\Http\Requests\StoreProcessRequest $request
* @return \Illuminate\Http\Response
*/
public function store(StoreProcessRequest $request)
{
$this->validate($request,[
'name'=>'required',
'email'=>'required',
'radicado'=>'required',
'NIT'=>'required',
'fecha'=>'required',
'user_id'=>'required',
]);
$process = new process;
$process->name = $request->name;
$process->email = $request->email;
$process->radicado = $request->radicado;
$process->NIT = $request->NIT;
$process->user_id = $request->userId;
$process->save();
return "Guardado";
}
storeProcessrequest
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
'email' => 'required',
'NIT' => 'required',
'fecha' => 'required',
'radicado' => 'required',
'user_id' => 'required',
];
}
process.blade
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-7">
<div class="card">
<div class="card-header">
<div class="row justify-content-center">
<div class="col-md-8" align="center">
<h1> {{ __('process') }}</h1>
</div>
</div>
</div>
<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
<form method="POST" action="{{ route('process.store') }}">
@csrf
<div class="row mb-6">
<label for="radicado" class="col-md-2 col-form-label text-md-right"> </label>
<div class="col-md-8">
<input id="radicado" type="text" class="form-control" name="radicado" placeholder=" radicado" required>
</div>
</div>
<div class="row mb-6">
<label for="fecha" class="col-md-2 col-form-label text-md-right"></label>
<div class="col-md-8">
<input id="fecha" class="form-control" type="text" name="Ingresar-fecha" placeholder="Fecha"
onclick="ocultarError();" onfocus="(this.type='date')" onblur="(this.type='text')" required>
</div>
</div>
<div class="row mb-6">
<label for="name" class="col-md-2 col-form-label text-md-right"></label>
<div class="col-md-8">
<input id="name" type="text" class="form-control" name="name" placeholder="Nombre" required>
</div>
</div>
<div class="row mb-6">
<label for="NIT" class="col-md-2 col-form-label text-md-right"></label>
<div class="col-md-8">
<input id="NIT" type="text" class="form-control" name="NIT" placeholder="NIT" required>
</div>
</div>
<div class="row mb-6">
<label for="email" class="col-md-2 col-form-label text-md-right"></label>
<div class="col-md-8">
<input id="email" type="email" class="form-control" name="email" placeholder="E-MAIL" required>
</div>
</div>
<div class="card-body">
@livewire('user-selector-component')
</div>
<div class="row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Crear') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
路线
Route::post('process.store', [App\Http\Controllers\ProcessController::class, 'store'])->name('process.store');
迁移
ID();
$table->字符串('radicado');
$table->字符串('fecha');
$table->字符串('name');
$table->字符串('NIT');
$table->字符串('email');
$table->foreignId('user_id');
$table->时间戳();
});
}
/**
* 反转迁移。
*
* @return无效
*/
public 函数向下()
{
Schema::dropIfExists('processs');
}
}
在“日期”字段中,名称不匹配,之前:name="Ingresar-fecha",现在:name="date",仅此而已。
当我提交表单时,它不会将信息保存在数据库中,而只是刷新页面,如果我在控制器中删除与我的请求的关系,记录将保存在数据库中,但因为我可以'使用$request,数据null到达
控制器
* @param \App\Http\Requests\StoreProcessRequest $request
* @return \Illuminate\Http\Response
*/
public function store(StoreProcessRequest $request)
{
$this->validate($request,[
'name'=>'required',
'email'=>'required',
'radicado'=>'required',
'NIT'=>'required',
'fecha'=>'required',
'user_id'=>'required',
]);
$process = new process;
$process->name = $request->name;
$process->email = $request->email;
$process->radicado = $request->radicado;
$process->NIT = $request->NIT;
$process->user_id = $request->userId;
$process->save();
return "Guardado";
}
storeProcessrequest
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
'email' => 'required',
'NIT' => 'required',
'fecha' => 'required',
'radicado' => 'required',
'user_id' => 'required',
];
}
process.blade
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-7">
<div class="card">
<div class="card-header">
<div class="row justify-content-center">
<div class="col-md-8" align="center">
<h1> {{ __('process') }}</h1>
</div>
</div>
</div>
<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
<form method="POST" action="{{ route('process.store') }}">
@csrf
<div class="row mb-6">
<label for="radicado" class="col-md-2 col-form-label text-md-right"> </label>
<div class="col-md-8">
<input id="radicado" type="text" class="form-control" name="radicado" placeholder=" radicado" required>
</div>
</div>
<div class="row mb-6">
<label for="fecha" class="col-md-2 col-form-label text-md-right"></label>
<div class="col-md-8">
<input id="fecha" class="form-control" type="text" name="Ingresar-fecha" placeholder="Fecha"
onclick="ocultarError();" onfocus="(this.type='date')" onblur="(this.type='text')" required>
</div>
</div>
<div class="row mb-6">
<label for="name" class="col-md-2 col-form-label text-md-right"></label>
<div class="col-md-8">
<input id="name" type="text" class="form-control" name="name" placeholder="Nombre" required>
</div>
</div>
<div class="row mb-6">
<label for="NIT" class="col-md-2 col-form-label text-md-right"></label>
<div class="col-md-8">
<input id="NIT" type="text" class="form-control" name="NIT" placeholder="NIT" required>
</div>
</div>
<div class="row mb-6">
<label for="email" class="col-md-2 col-form-label text-md-right"></label>
<div class="col-md-8">
<input id="email" type="email" class="form-control" name="email" placeholder="E-MAIL" required>
</div>
</div>
<div class="card-body">
@livewire('user-selector-component')
</div>
<div class="row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Crear') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
路线
Route::post('process.store', [App\Http\Controllers\ProcessController::class, 'store'])->name('process.store');
迁移
ID(); $table->字符串('radicado'); $table->字符串('fecha'); $table->字符串('name'); $table->字符串('NIT'); $table->字符串('email'); $table->foreignId('user_id'); $table->时间戳(); }); } /** * 反转迁移。 * * @return无效 */ public 函数向下() { Schema::dropIfExists('processs'); } }在“日期”字段中,名称不匹配,之前:name="Ingresar-fecha",现在:name="date",仅此而已。