路由模型绑定未触发 [英] Route Model Binding Not Firing

查看:63
本文介绍了路由模型绑定未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些路线/模型绑定设置.其中大约十个用于各种ID.没什么特别的:

I have some route/model bindings setup. Around ten of them for various ids. Nothing special going on:

$router->get('/notifications/{active_notification_id}/open', 'NotificationsController@open');

$router->bind('active_notification_id', function ($id)
{
    echo 'here'; echo $id; exit;

    // code
});

绑定根本没有触发.在另外八个中工作正常,但是对于其中两个来说,它不会触发.它直接进入带有空模型的控制器,这会导致我的代码崩溃.

The binding is not firing at all. Works fine in eight others but for two of them it just doesn't fire. It goes straight to the controller with an empty model which than crashes my code.

更疯狂的事情是,它们都可以在我的本地机器上正常工作(Windows),但只能在服务器(Ubuntu)上遇到此问题.我的php版本只有一个次要版本.但是其中8个绑定有效,只是这两个绑定不会触发.

The crazier thing is they ALL work on my local box just fine (Windows) but only having this issue on server (Ubuntu). My php versions are off by just one minor version. But 8 of the bindings work, it's just those two simply won't fire.

有人有主意吗?

  • 请注意,我的Laravel和软件包版本在两端都相同.

更新:所以实际上看来我的路线都不会在生产中回显.我假设"其他人在工作,因为他们工作正常.我还尝试编辑src/Illuminate/Routing/Router.php bind()函数以回显某些内容,但看不到它在生产中回显(在本地显示).

UPDATE: So actually it seems none of my routes will echo out on production. I "assumed" the others were working because they worked correctly. I also tried editing the src/Illuminate/Routing/Router.php bind() function to echo something but can't see it echo on production (does on local).

在生产环境中必须有某种类/文件缓存.不知道这是Laravel问题还是我的DigitialOcean包装盒有问题.

There must be some kind of class/file caching on my production box. Not sure if this is Laravel issue or something with my DigitialOcean box.

推荐答案

这可能是由于Laravels预编译所致.

This is probably due to Laravels pre-compiling.

框架预编译基本上用于每个请求的某些类.这用于性能优化的目的.可以在files下的config/compile.php中指定要编译的文件. 默认值如下:

The framework pre-compiles certain classes that are used on basically every request. This serves the purpose of performance optimization. Files to compile can be specified in config/compile.php under files. The default one looks like this:

'files' => [
    realpath(__DIR__.'/../app/Providers/AppServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/BusServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/ConfigServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/EventServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/RouteServiceProvider.php'),
],

在运行php artisan optimize时,如果未启用调试(或使用--force选项),则列出的那些文件和其他框架类将被写入storage/framework/compiled.php. (在Laravel 5.0.16中,路径已更改为vendor/compiled.php)

When running php artisan optimize when debugging is not enabled (or with the --force option) Those listed files and other framework classes will be written to storage/framework/compiled.php. (in Laravel 5.0.16 the path has been changed to vendor/compiled.php)

尝试运行php artisan clear-compiledphp artisan optimize,应使用您的新" RouteServiceProvider.

Try running php artisan clear-compiled or php artisan optimize and your "new" RouteServiceProvider should be used.

php artisan optimize,因为它已注册为发布脚本:

php artisan optimize is called every time you run composer update composer install (and composer create-project) because it is registered as post script:

"scripts": {
    "post-install-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "post-update-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ]
},

这篇关于路由模型绑定未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆