Laravel을 사용하여 양식을 데이터베이스에 저장 한 후 페이지를 리디렉션하는 방법은 무엇입니까?

Jerielle

이것에 문제가 있습니다. 저는 라 라벨을 공부하고 있고 양식을 만들고 있습니다. 내 간단한 시나리오는 다음과 같습니다. 사용자가 등록 양식을 완료 한 후 제출 버튼을 클릭해야합니다. 그런 다음 유효성 검사가 있으면 표시되어야하며 양식은 저장되지 않아야합니다. 오류가 없으면 저장해야합니다. 그리고 홈페이지로 이동합니다. 내 오류는 데이터베이스에 데이터를 저장 한 후 페이지를 인덱스로 리디렉션 할 수 없다는 것입니다. 403 금지 페이지 오류가 표시됩니다.

내 경로의 코드는 다음과 같습니다.

Route::model('employee','Employee');

Route::get('/','EmployeesController@index');
Route::get('/register', 'EmployeesController@register');
Route::get('/handleRegister', 'EmployeesController@handleRegister');

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('EmployeesController@index');

        }

    }
);

내 색인 기능은 다음과 같습니다.

public function index()
    {
        return View::make('index', array(
            'page_title'    => 'Flax: Food Ordering',
            'login_footer'  => 'Flax Inc. @ '. date('Y'),
            'register_link' => action('EmployeesController@register')
        ));
    }

그런 다음 내 브라우저에 다음이 있습니다.

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

URL에서 다음을 발견했습니다.

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 /          |      | EmployeesController@index    |                |               |
|        | GET|HEAD register   |      | EmployeesController@register |                |               |
|        | POST handleRegister |      | Closure                      |                |               |
+--------+---------------------+------+------------------------------+----------------+---------------+
마르신 나비아 웨크

변경하려고

return Redirect::action('EmployeesController@index');

으로:

return Redirect::to('/');

여기에 오류가 표시되지 않지만 호스트 이름의 밑줄로 인해이 문제가 발생할 수 있습니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관