octobercms / october

Self-hosted CMS platform based on the Laravel PHP Framework.
https://octobercms.com/
Other
11.01k stars 2.21k forks source link

I need laravel5.4, can I update that package? #2907

Closed iamike closed 7 years ago

iamike commented 7 years ago
Expected behavior

When I using laravel updateOrCreate feature, which is really cool.

        $wechatPassport = WechatPassport::updateOrCreate(
          ['union_id' => $userInfo->unionId],
          [
            'headimgurl' => $userInfo->avatarUrl,
            'nickname' => $userInfo->nickName,
            'province' => $userInfo->province,
            'sex' => $userInfo->gender,
            'country' => $userInfo->country,
          ]
        );
Actual behavior

It says error....I dont recognize this method....

Reproduce steps

check composer.json "require": { "php": ">=5.5.9", "october/rain": "~1.0", "october/system": "~1.0", "october/backend": "~1.0", "october/cms": "~1.0", *"laravel/framework": "5.1.",** "wikimedia/composer-merge-plugin": "dev-master" },

October build

(October build number)

Eoler commented 7 years ago

Not yet, but soon: https://octobercms.com/support/article/rn-9

daftspunk commented 7 years ago

Should be fixed in Build 420+

However this is easy enough to do now with firstOrNew

$wechatPassport = WechatPassport::firstOrNew(['union_id' => $userInfo->unionId]);

$wechatPassport->fill([
    'headimgurl' => $userInfo->avatarUrl,
    'nickname' => $userInfo->nickName,
    'province' => $userInfo->province,
    'sex' => $userInfo->gender,
    'country' => $userInfo->country,
])->save();
LukeTowers commented 7 years ago

@daftspunk @iamike That method does exist in 5.1, I've used it myself. In fact, it's existed since at least 4.2. (https://github.com/laravel/framework/blob/4.2/src/Illuminate/Database/Eloquent/Model.php#L553) See https://stackoverflow.com/a/20764237/6652884. I believe this is probably some other issue that you are running into.

daftspunk commented 7 years ago

@LukeTowers You'll find updateOrCreate doesn't exist. The above code using firstOrNew is an exact replica of the functionality.