Search code examples
laravel-4url-routingproduction-environment

Laravel 4 - some but not all routes failing on production


I have an application which has been running successfully for over a year on both the production server and my development machine (both running IIS without any pretty URLs). Yesterday I moved the latest in a series of (until now successful) updates from development to production, and since then many of the routes have been failing on the production server, even though they work fine on dev. I've verified that the exact same application and route files are present on both machines, I've confirmed that php artisan routes produce the same output on both machines, I've confirmed that their autoload_classmap.php files are identical, and I've verified that both servers are running Laravel 4.1.23 .

After some testing it appears that, for example, the URL https://localhost/EPHY/index.php/child/3958/edit, which triggers the ChildController::edit() RESTful method on dev, triggers ChildController::create() on production, which then crashes because it can't find the familyId parameter it's expecting. Here's the applicable line in routes.php on both servers:

Route::resource( 'child', 'ChildController', array( 
    'create'  => 'child.create', 
    'store'   => 'child.store', 
    'show'    => 'child.show', 
    'edit'    => 'child.edit', 
    'update'  => 'child.update', 
    'destroy' => 'child.destroy'
));

I should note that Family, another RESTful resource, works successfully on both servers, but others don't. After doing some more testing, it actually seems like any routes relating to models that have an Eloquent relationship with Family are failing, and all the others are working fine. That's just weird...

Can anybody suggest what may be causing this, or at least where I can look? I'm happy to post additional information.

UPDATE: I continue to poke at this problem, and it's becoming apparent that this is definitely only affecting routes related to models with an Eloquent relationship to the Family model; all other routes in the application appear to be working correctly.


Solution

  • Ok, I figured this out, and it's lame. As I noted above, this was only affecting models which had an Eloquent relationship with Family. What that means in practice is that all of the ::create() methods of the associated Controllers needed the Family::id value. So, here's the code I was checking the determine whether I needed that value from Input::get() or Input::old(): $familyId = ( empty( Input::old() ) )? Input::get('familyId') : Input::old('family_id');

    Anybody see the problem? empty() can't take a function call as a parameter. Everything worked fine as soon as I changed the code to:

    $familyId = ( Input::old() )? Input::old('family_id') : Input::get('familyId') ;
    

    Now, how did I figure this out? Well, after spending a day and a half assuming I knew what "Can't use function return value in write context" meant, I FINALLY CHECKED THE DAMN ERROR MESSAGE ON GOOGLE! Let this be a lesson to the newbs and a reminder to the veterans, never assume you understand what an error means without double-checking with the groupmind...

    I'm so ashamed...