我不明白为什么,但是当我尝试在数据库中发布表单“ entreprise”时,所有值均为null。
在目前的代码中,我仅使用形式为nomEntreprise的一个数据测试所有内容。
web.php
我使用两条路线:一条返回我的视图,另一条发布我的数据
Route::get('/entreprise/', 'EntrepriseController@index')->name('entreprise');
Route::post('store', 'EntrepriseController@store');
EntrepriseController.php
<?php
namespace App\Http\Controllers;
use App\Http\Requests\EntrepriseRequest;
use App\postEntreprise;
class EntrepriseController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('auth/entreprise');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function store(EntrepriseRequest $request)
{
$content = [];
$contact['nomEntreprise'] = $request->post('nomEntreprise');
var_dump ($request->post());
return 'test';
}
EntrepriseRequest.php
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class EntrepriseRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'nomEntreprise' => ''
];
}
}
entreprise.blade.php 我为表单使用一个模板
@extends('layouts.form')
@extends('layouts.app')
@section('card')
@component('components.card')
<form method="post" action="store">
{{ csrf_field() }}
@include('partials.form-group', [
'logo' => 'mdi mdi-account',
'type' => 'text',
'name' => 'nomEntreprise',
'placeholder' => 'Nom d\'entreprise',
'required' => true,
])
@include('partials.form-group', [
'logo' => 'mdi mdi-home',
'type' => 'text',
'name' => 'address_1',
'placeholder' => 'Adresse 1',
'required' => true,
])
@include('partials.form-group', [
'logo' => 'mdi mdi-home',
'type' => 'text',
'name' => 'address_2',
'placeholder' => 'Adresse 2',
'required' => false,
])
@include('partials.form-group', [
'logo' => 'mdi mdi-home',
'type' => 'text',
'name' => 'cp',
'placeholder' => 'Code Postal',
'required' => true,
])
@include('partials.form-group', [
'logo' => 'mdi mdi-home',
'type' => 'text',
'name' => 'ville',
'placeholder' => 'Ville',
'required' => true,
])
@include('partials.form-group', [
'logo' => 'mdi mdi-web',
'type' => 'text',
'name' => 'www',
'placeholder' => 'Site Web',
'required' => true,
])
@include('partials.form-group', [
'logo' => 'mdi mdi-email',
'type' => 'email',
'name' => 'email',
'placeholder' => 'Email de Contact de L\'entreprise',
'required' => true,
])
@include('partials.form-group', [
'logo' => 'mdi mdi-phone-classic',
'type' => 'text',
'name' => 'telephone_1',
'placeholder' => 'Téléphone',
'required' => true,
])
@include('partials.form-group', [
'logo' => 'mdi mdi-cellphone-android',
'type' => 'text',
'name' => 'telephone_2',
'placeholder' => 'Portable',
'required' => true,
])
@include('partials.form-group', [
'logo' => 'mdi mdi-fax',
'type' => 'text',
'name' => 'fax',
'placeholder' => 'Fax',
'required' => true,
])
@component('components.button')
@lang('Inscription')
@endcomponent
</form>
@endcomponent
@endsection