我是laravel的新手,創建了所需的全部內容,但我無法編輯或向數據庫添加新條目。不過,我可以成功刪除。沒有使應用程序寫入數據庫的問題是什麼?無法將信息保存到數據庫
這是你store
方法我的存儲功能
public function store(Request $request)
{
//validate data
$validation=$this->validate($request, [
'username' => 'required|max:50',
'role_id' => 'required|max:50',
'email' => 'required|email|max:50',
]);
$user = new User;
$user->username = $request->username;
$user->role_id = $request->role_id;
$user->email = $request->email;
$user->save();
// redirect
Session::flash('message', 'Successfully added the record!');
Session::flash('alert-type', 'success');
return Redirect::to('user');
}
路線
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function() {
return view('auth.login');
});
Route::auth();
Route::get('/home', '[email protected]');
Route::resource('user', 'UserController');
Route::resource('role', 'RoleController');
你能告訴我們一些代碼? –
編輯後我剛剛在上面加入了它 –
您是否收到錯誤? – Komal