我有一個項目將有8種不同的形式,全部更新我的數據庫中的相同「用戶」表。我有用戶身份驗證工作,並使我的localhost mysql數據庫中的表中的用戶。但是,當我開始更新表,我不斷收到錯誤,如電子郵件是不唯一或HTTP錯誤或RouteDependencyResolverTrait.php中的ReflectionException第57行:內部錯誤:無法檢索默認值。 我已經嘗試了一切,我創建的作品,但它使一個新的行,並不會更新用戶已登錄的現有行。不知道爲什麼我的表單沒有更新數據庫中的值
我只是Laravel 5.4的新手,完成了所有的Laracasts,所以我絕對不知道該怎麼做。
有沒有人有任何想法或知道如何解決它或重構它更好?請讓我知道如果我錯過了任何東西。我一直試圖讓這個工作2天。
Basics.php
<?php
namespace App;
class Basics extends Model
{
public $table = "users";
protected $fillable = [
'family_name',
'given_names'
];
}
BasicsController.php
class BasicsController extends Controller
{
public function index()
{
$user = \Auth::user();
return view('/details/basics', compact('user'));
}
public function update(Request $request, $id)
{
$basics = Basics::find($id);
$basics->family_name = $request->input('family_name');
$basics->given_names = $request->input('given_names');
$basics->save();
return redirect("/details/basics");
}
}
basics.blade.php
@extends ('layouts/app')
@section ('content')
{{--Do @includes for all form components with the components file--}}
@include ('layouts/header')
<main class="main">
<form action="/details/basics" method="POST">
<input type="hidden" name="_method" value="PATCH">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<fieldset>
<label>Family name</label>
<input type="text" name="family_name" placeholder="Family name" value="{{ old('family_name') }}" />
</fieldset>
<fieldset>
<label>Given names</label>
<input type="text" name="given_names" placeholder="Given names" value="{{ old('given_names') }}" />
</fieldset>
<button type="submit" value="Save" name="save" class="button button-primary button-wide">Save</button>
</form>
</main>
@endsection
web.php
Route::get('/', function() {
return view('welcome');
});
// Authentication Routes
Auth::routes();
Route::get('/logout', 'Auth\[email protected]');
Route::get('/home', '[email protected]');
Route::get('/dashboard', function() {
$user = Auth::user();
return view('dashboard', compact('user'));
});
// Eligibility Assessments
Route::get('/assessment/student', '[email protected]');
Route::post('/assessment/results', '[email protected]');
// Details
Route::get('/details/basics', '[email protected]');
Route::patch('/details/basics', '[email protected]');
/您是否使用laravel的'make:auth'?你在表格中有'email'字段嗎? –
是的,我使用make:auth並且在表 – aszet