Laravel - MariaDB服务器版本,用于在附近使用正确的语法

时间:2017-05-24 16:43:32

标签: php mysql laravel mariadb

我试图在天际表中找到user_id等于1的Payouts及其关系。

我执行的代码是:

$user_payout = Payout::fromTable('skyrim')->where('user_id',1)->with('game','cluster')->first();
        dd($user_payout);

它给了我这个错误:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'where user_id = ? limit 1' at line 1 (SQL: select * where user_id = 1 limit 1)

为什么这不起作用?

1 个答案:

答案 0 :(得分:1)

首先尝试获取数据然后执行关系的急切加载

$model = (new Payout)->setTable('skyrim')->where('user_id', 1)->first();

if($model) {
    $model->load('game','cluster');
}