Hi, Im developing a really simple application in laravel 5, for now only shows blog post and nothing else. It uses SqlLite and for now it has only 4 tables (users, articles, tags, article_tag). My local machine has PHP 5.6.6 (Arch Linux) and my production server has PHP 5.5.22 (CentOs 6) and Apache 2.4 both on them.
Im having problems with my route model bindings, I think since last composer update (today) they stop working only in my server (PHP 5.5.22 as I said).
These are my files:
app/Providers/RouteServiceProvider.php
namespace App\Providers;
use Illuminate\Routing\Router;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider {
protected $namespace = 'App\Http\Controllers';
public function boot(Router $router)
{
parent::boot($router);
$router->bind('test', function($test) {
return \App\Article::findOrFail($test);
});
}
public function map(Router $router)
{
$router->group(['namespace' => $this->namespace], function($router)
{
require app_path('Http/routes.php');
});
}
}
app/Controllers/TestController.php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class TestController extends Controller {
public function show(Article $test) {
return $test->title;
}
}
app/routes.php
Route::get('test/{test}', 'TestController@show');
Results:
If I go to test/1 in my local machine it gives me the title of the article as I expected, but in my server it gives me null.
Using tinker in my server:
$test = \App\Article::findOrFail(1)->title
Gives me the correct information.
If I dd() $test inside the show method, in my local machine gives me the full object with all the correct information for the article 1. In my server gives me an empty Article object. If I change:
public function show(Article $test)
To:
public function show($test)
In my local machine gives me the full Article object with the correct information. In my server gives me the argument passed to the url, in this case 1.
If I add these lines to the app\routes.php at the start:
Route::bind('test', function($test) {
return \App\Article::findOrFail($test);
});
Everything works fine in both machines.
Steps to reproduce:
composer update composer dump-autoload -o: after the update artisan cache:clear clear-compiled: after the update PHP 5.5.22 in the server machine.
Laravel Version: Laravel 5.0.18
Other Packages installed via composer:
"hieu-le/active" : "~2.0",
"illuminate/html": "5.*",
"intervention/image": "~2.1",
"intervention/imagecache": "~2.1"
I'm not sure if this is a bug or just I am missing something, that's why I'm posting here. In fact, I'm not entirely sure if the problem started with the update, I just can't remember, .
Sorry for my english, is not my native language.
Thanks.
The problem was the update to 5.0.16. My app was using an old compiled file and php artisan clear-compiled wasn't working due to the change introduced in 5.0.16 laravel/framework@cfa7fcb
The solution was follow the Upgrade guide to 5.0.16, then php artisan clear-compiled and everything is working fine again.
Thanks
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community