我有這個問題。我正在學習Laravel,我正在建立一個表格。我的簡單情況就是這樣。用戶完成註冊表單後,他們需要點擊提交按鈕。那麼如果有驗證,它應該顯示並且表單不應該保存。如果沒有錯誤,應該保存。並重定向到主頁。我的錯誤是,將數據保存到數據庫後,我無法將頁面重定向到索引。它將顯示一個錯誤403禁止頁面。如何使用Laravel將表單保存到數據庫後重定向頁面?
下面是我的路線代碼:
Route::model('employee','Employee');
Route::get('/','[email protected]');
Route::get('/register', '[email protected]');
Route::get('/handleRegister', '[email protected]');
Route::post('/handleRegister', function()
{
$rules = array(
'emp_code' => 'numeric',
'lastname' => 'required|min:2|max:15',
'firstname' => 'required|min:2|max:20',
'middlename' => 'min:2|max:20',
'password' => 'required|min:8|max:30',
'cpassword' => 'required|same:password'
);
$validator = Validator::make(Input::all(), $rules);
if($validator->fails()) {
$messages = $validator->messages();
return Redirect::to('register')
->withErrors($messages)
->withInput(Input::except('password','cpassword'));
} else {
$employee = neW Employee;
$employee->emp_code = Input::get('emp_code');
$employee->lastname = Input::get('lastname');
$employee->firstname = Input::get('firstname');
$employee->middlename = Input::get('middlename');
$employee->gender = Input::get('gender');
$employee->birthday = Input::get('birthday');
$employee->password = Hash::make(Input::get('password'));
$employee->save();
return Redirect::action('[email protected]');
}
}
);
這裏是我的索引功能:
public function index()
{
return View::make('index', array(
'page_title' => 'Flax: Food Ordering',
'login_footer' => 'Flax Inc. @ '. date('Y'),
'register_link' => action('[email protected]')
));
}
然後在我的瀏覽器我有這樣的:
Forbidden
You don't have permission to access /http://dev.flax_order.local on this server.
Apache/2.4.9 (Win64) OpenSSL/1.0.1g PHP/5.5.12 Server at dev.flax_order.local Port 80
在我注意到網址這個:
http://dev.flax_order.local/http://dev.flax_order.local
它使鏈接加倍。
我不知道我的錯誤在哪裏。你能幫助我嗎?
這裏的方式是從運行
php artisan routes
C:\wamp\vhosts\flax_order>php artisan routes
+--------+---------------------+------+------------------------------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------+---------------------+------+------------------------------+----------------+---------------+
| | GET|HEAD/ | | [email protected] | | |
| | GET|HEAD register | | [email protected] | | |
| | POST handleRegister | | Closure | | |
+--------+---------------------+------+------------------------------+----------------+---------------+
把你的路線文件和索引操作。 – itachi 2014-10-28 06:47:12
好的,我編輯了這些問題。 :) – Jerielle 2014-10-28 06:52:46
EmployeesController @ index的代碼位於頂端,它是我的索引函數。我包括在我的問題 – Jerielle 2014-10-28 07:02:45