My problem: when I do GET /print-jobs/
, it correctly routes to the index
method in my controller. When I say POST /print-jobs/
, it should route to my store
method. However, it seems to be routing to my index
method as well. This only happens in my production environment, where I am running Laravel under Apache.
Route code:
Route::group(['prefix' => 'print-jobs'], function () {
Route::get('/', 'PrintJobMasterController@index');
Route::get('/{printJob}', 'PrintJobMasterController@show')->where(['printJob' => '[0-9]+']);
Route::post('/', 'PrintJobMasterController@store');
...
}
Relevant controller code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class PrintJobMasterController extends Controller {
/**
* Display all PrintJob models
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request) {
Log::info('PJMC::index: rendering index of all print jobs');
...;
}
/**
* Store a newly job request en masse
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request) {
Log::info("PJMC::store: creating new job");
...;
}
...;
}
Now, I expect to see in my logs a message starting with PJMC::index:
when I call GET /print-jobs/
and a message starting with PJMC::store:
when I call POST /print-jobs/
. However, both times when do this in the browser: $.get('/print-jobs')
and $.post('/print-jobs/', {_token: window.Laravel.csrfToken, ...})
from my browser, I see the following in my log file:
[2017-06-09 10:27:17] local.INFO: PJMC::index: rendering index of all print jobs [2017-06-09 10:27:23] local.INFO: PJMC::index: rendering index of all print jobs
Both times the request routes to the index
method! I looked in my network history on my browser and the requests are indeed registered as a GET
and a POST
respectively, which leads me to suspect that the problem is somewhere on the backend. However, when I call these routes using Laravel's test suite, I don't have any problems.
Any ideas? Thanks in advance.