【问题标题】:Laravel Model reference inside Controller gives error while hosted on HerokuController 中的 Laravel 模型引用在 Heroku 上托管时出现错误
【发布时间】:2021-04-08 12:44:35
【问题描述】:

我在 Laravel 中构建了一个 Lingo 游戏。该应用托管在 Heroku 上:https://lingo-hu.herokuapp.com

每当我单击“开始游戏”按钮时,它都会向我的 WordController 发送一个 HTTP-POST-REQUEST。这样做后,它会给出以下响应:

"message": "Attempt to read property \"word\" on null",
"exception": "ErrorException",
"file": "/app/app/Http/Controllers/WordController.php",
"line": 23,

我的 WordController 对“word”模型的引用:

    namespace App\Http\Controllers;
    
    use App\word;
    use App\game;
    
    use Illuminate\Contracts\Routing\ResponseFactory;
    use Illuminate\Http\Request;
    
    class WordController extends Controller
    {
    }

但是,当在本地运行 Laravel 时,此操作在我的计算机上确实有效,只是在我不理解的 Heroku 上无效。

控制台错误:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)
app.js:699 Uncaught (in promise) Error: Request failed with status code 500
    at createError (app.js:699)
    at settle (app.js:960)
    at XMLHttpRequest.handleLoad (app.js:168)

数据库已启动并正在运行,我使用了php artisan migrate,它正在工作。

有人对我可能做错的地方提出建议吗?

【问题讨论】:

  • 提供错误实际指代的代码......

标签: laravel heroku deployment


【解决方案1】:

这个错误是因为 Word 模型所引用的数据库表是空的。所以我从我的 MySQL 数据库中导入了一个导出。现在可以了!

【讨论】:

    猜你喜欢
    • 2016-05-24
    • 1970-01-01
    • 1970-01-01
    • 2020-07-21
    • 2016-07-30
    • 2016-04-23
    • 2020-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多