Laravel Put Route Giving 404 錯誤 (Laravel Put Route Giving 404 Error)


問題描述

Laravel Put Route Giving 404 錯誤 (Laravel Put Route Giving 404 Error)

So I have been trying to use the "put" method in my routing, I have followed this example directly from the "routes.php" file:

Route::put('hello/(:any)', function($name)
{
      return "Welcome, $name.";
});

This returns a 404 error, I really want my code to look like below. I want to be able to take to parameters from the url and use them for verification, later on I plan to use an encoding method but for now I just wanted to get the routes working properly before I tried encoding them. Any help would be greatly appreciated!!!

Route::put('admin/activate/(:any?)/(:any?)', function($r, $e) {
     return "Random value: $r <br/> Email: $e";
});

You can find the page here: http://diverseevolution.com/admin/activate/randomstring/test@gmail.com

Here is my overall "routes.php" file:

Route::get('/', function() {
     return View::make('homepage.index');
});

///////////////////////////////////////////////////////////////////////////////////////////
///////////////        Administration Account Creation & Login        /////////////////////
///////////////////////////////////////////////////////////////////////////////////////////

// Create account
Route::get('admin/createform', function() {
     return View::make('admin.createform');
});

// action for actual admin creation
Route::post('admin/create', array('before' => 'csrf', function() {
     $rules = array(
          'fname' => 'required|min:3',
          'lname' => 'required|min:3',
          'email' => 'required|email|unique:users',
          'pword' => 'required'
     );

     $validated = Validator::make(Input::all(), $rules);

     if($validated ‑> fails()) {
          return Redirect::to('admin/createform')‑>with_input();
     } else {
          $r = Hash::make(time() .'ReAl19dk4‑^4$'. $_POST['pword']);

          $user = new User;

          $user ‑> fname = $_POST['fname'];
          $user ‑> lname = $_POST['lname'];
          $user ‑> email = $_POST['email'];
          $user ‑> pword = Hash::make($_POST['pword']);
          $user ‑> status = 'unactivated';
          $user ‑> random = $r;

          if($user ‑> save()) {

               //////////////////////// Email /////////////////////////////////
               // We still need to make this functionality

               $msg = '
               <h1>Your admin account has been created!</h1>
               <p>Congratulations on creating your new account, there is one last step before your account can be activated. Below is a link, simply follow the link to activate your account, once you have your account will be active and you will be able to login!</p>
               <p><a href="http://diverseevolution.com/admin/activate/'. $r .'/'. $_POST['email'] .'">http://diverseevolution.com/admin/activate/'. $r .'/'. $_POST['email'] .'</a></p>
               <p>Thanks, Diverse Evolution</p>
               ';

                    // Mail headers
                    $headers  = "Reply‑To: Diverse Evolution <info@diverseevolution.com>\r\n"; 
                    $headers .= "Return‑Path: Diverse Evolution <info@diverseevolution.com>\r\n"; 
                    $headers .= "From: Diverse Evolution <info@diverseevolution.com>\r\n"; 
                    $headers .= "Organization: Diverse Evolution\r\n";
                    $headers .= 'MIME‑Version: 1.0' . "\r\n";
                    $headers .= 'Content‑type: text/html; charset=iso‑8859‑1' . "\r\n";
                    $headers .= "X‑Priority: 3\r\n";
                    $headers .= "X‑Mailer: PHP". phpversion() ."\r\n";
                    define('_headers', $headers);

               if(mail($_POST['email'], 'Diverse Evolution Account Created', $msg, _headers)) {
                    return Redirect::to('admin/thanks');
               } else {

               }
          } else {
               return Redirect::to('admin/createform')‑>with_input();
          }

     }
}));

// creates the thank you page for the admin account creation
Route::get('admin/thanks', function() {
     return View::make('admin/thanks');
});

// account activation email, this is still not working 011613
Route::put('admin/activate/(:any?)/(:any?)', function($r, $e) {
     return "Random value: $r <br/> Email: $e";
});

// Login form
Route::get('admin/loginform', function() {
     return View::make('admin/loginform');
});

// Login action
Route::post('admin/login', array('before' => 'csrf', function() {
     $rules = array(
          'email' => 'required|email',
          'pword' => 'required'
     );

     $validated = Validator::make(Input::all(), $rules);

     if($validated ‑> fails()) {
          return Redirect::to('admin/loginform')‑>with_input();
     } else {
          $credentials = array('username' => $_POST['email'], 'password' => $_POST['pword']);

          if (Auth::attempt($credentials)) {
               return Redirect::to('admin/dash');
          } else {
               return Redirect::to('admin/loginform')‑>with_input();
          }
     }
}));

Route::get('admin/logout', function() {
     Auth::logout();
     return Redirect::to('admin/loginform');
});

///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////        Administration Pages        ////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
Route::group(array('before' => 'auth'), function() {
    Route::get('admin/dash', function() {
        return 'Dashboard';
    });
});















/*
|‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
| Application 404 & 500 Error Handlers
|‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
|
| To centralize and simplify 404 handling, Laravel uses an awesome event
| system to retrieve the response. Feel free to modify this function to
| your tastes and the needs of your application.
|
| Similarly, we use an event to handle the display of 500 level errors
| within the application. These errors are fired when there is an
| uncaught exception thrown in the application.
|
*/

Event::listen('404', function()
{
    return Response::error('404');
});

Event::listen('500', function()
{
    return Response::error('500');
});

/*
|‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
| Route Filters
|‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
|
| Filters provide a convenient method for attaching functionality to your
| routes. The built‑in before and after filters are called before and
| after every request to your application, and you may even create
| other filters that can be attached to individual routes.
|
| Let's walk through an example...
|
| First, define a filter:
|
|       Route::filter('filter', function()
|       {
|           return 'Filtered!';
|       });
|
| Next, attach the filter to a route:
|
|       Route::get('/', array('before' => 'filter', function()
|       {
|           return 'Hello World!';
|       }));
|
*/

Route::filter('before', function()
{
    // Do stuff before every request to your application...
});

Route::filter('after', function($response)
{
    // Do stuff after every request to your application...
});

Route::filter('csrf', function()
{
    if (Request::forged()) return Response::error('500');
});

Route::filter('auth', function()
{
    if (Auth::guest()) return Redirect::to('admin/loginform');
});

‑‑‑‑‑

參考解法

方法 1:

You didnt include your form ‑ but I'm guessing you didnt include a "PUT" in the form.

echo Form::open('user/profile', 'PUT');

You can see more about forms and PUT here. But in general, you need to specifically include PUT in your form, otherwise it will just be POST (browser default).

方法 2:

Using GET works?

or

Route::put('hello/(:all)', function($name)
{
      return "Welcome, $name.";
});

all becouse @

(by Tom BirdLaurenceRamiroRS)

參考文件

  1. Laravel Put Route Giving 404 Error (CC BY‑SA 3.0/4.0)

#http-status-code-404 #Laravel #PHP #frameworks #routes






相關問題

PHP在simplexml print_r上返回頁面錯誤 (PHP returning page error on simplexml print_r)

Apache Camel 和 CXF:多個 cxf:rsServer 標籤 .. 這可能嗎? (Apache Camel and CXF: Mutlitple cxf:rsServer tags .. is this possible?)

Penyiapan situs MSM 5 dengan pengalihan halaman 404 umum (MSM 5 site setup with a common 404 page redirect)

Успадкоўванне кантролера ASP.NET MVC 4 (ASP.NET MVC 4 controller inheritance)

Laravel Put Route Giving 404 錯誤 (Laravel Put Route Giving 404 Error)

WordPress 404 頁 (Wordpress 404 PAGE)

Gửi email tự động khi tải trang (Send Email Automatically On Page Load)

何時顯示“未找到記錄”頁面或返回 HTTP 404? (When to display "Record Not Found" Page or return HTTP 404?)

Breeze.js:處理空結果 (Breeze.js: Handling empty results)

如何從php中製作的404自定義頁面獲取用戶嘗試訪問的鏈接 (How to get the link that the user tried to visit, from a 404 custom page made in php)

Flask 文件上傳失敗並出現 404 錯誤 (Flask File Upload fails with 404 error)

如何在 ASP.NET 頁面中對超鏈接和內容進行變基? (How do you rebase hyperlinks and content in an ASP.NET page?)







留言討論