由於某種原因,我的表單沒有提交任何數據到數據庫,但它看起來很好,我站在哪裏,數據庫可以將這些信息調用到表單。Laravel表單不提交數據到數據庫
由於人們需要提交大量信息,因此我將配置文件的詳細信息作爲登錄過程的一部分。仍然不熟悉Laravel如何執行這些操作,但現在我大致瞭解了我一直在擺弄的過程。
我想知道的一件事是,是否有表單寫入數據庫的特定語法,我應該在表單中命名數據庫各自的表名?或者是控制器的那部分?
我應該使用表單模型綁定嗎?儘管如此,目前Laravel版本的信息有點難以找到。
我錯過了什麼?
//Route::get('NewUser', '[email protected]');
Route::post('NewUser', '[email protected]');
//Route::get('NewUser', '[email protected]')->name('NewUser');
Route::post('NewUser', '[email protected]')->name('submit');
控制器:
<?php
namespace App\Http\Controllers;
use App\UserEdit;
use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
class UserEntryController extends Controller
{
protected function create()
{
$id = UserEdit::find(715)->toArray();
return view('NewUser', compact('id'));
//return $array;
}
public function UserForm(Request $request) {
$email = $request['email'];
$first_name = $request['first_name'];
$password_hint = $request['password_hint'];
$last_name = $request['last_name'];
$user = UserEdit::find(715)->first();
$user->email = $email;
$user->First_Name = $first_name;
$user->Last_Name = $last_name;
$user->Password_Hint = $password_hint;
$user->save();
$id = UserEdit::find(715)->toArray();
return view('NewUser', compact('id'));
}
}
刀片:
@extends('layout')
@section('content')
<h1> Add Your Information {{ $id['name'] }}</h1>
<div class="row">
<div class="col-md-6">
<h3>Edit</h3>
<form action="{{ route('submit') }}" method="post">
<div class="form-group">
{{ csrf_field() }}
<label for="email">Your E-Mail</label>
<input class="form-control" type="text" name="email" id="email">
</div>
<div class="form-group">
{{ csrf_field() }}
<label for="first_name">Your First Name</label>
<input class="form-control" type="text" name="first_name" id="first_name">
</div>
<div class="form-group">
{{ csrf_field() }}
<label for="last_name">Your Last Name</label>
<input class="form-control" type="text" name="last_name" id="last_name">
</div>
<div class="form-group">
{{ csrf_field() }}
<label for="password_hint">Your Password Hint</label>
<input class="form-control" type="text" name="password_hint" id="password_hint">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<input type="hidden" name="_token" value="{{ Session::token() }}">
</form>
</div>
</div>
@foreach ($id as $key=>$value)
{{ $value }}<br>
@endforeach
@stop