本文整理汇总了PHP中tag::firstOrCreate方法的典型用法代码示例。如果您正苦于以下问题:PHP tag::firstOrCreate方法的具体用法?PHP tag::firstOrCreate怎么用?PHP tag::firstOrCreate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tag
的用法示例。
在下文中一共展示了tag::firstOrCreate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insertUsertag
public static function insertUsertag($user, $result)
{
$user_id = $user->id;
$token = $user->token;
if (!isset($result) || $result != '') {
$result = json_decode(file_get_contents("https://api.linkedin.com/v1/people/~:(id,first-name,last-name,skills,headline,summary,industry,member-url-resources,picture-urls::(original),location,public-profile-url,email-address)?format=json&oauth2_access_token={$token}"));
if (!empty($result->skills->values)) {
Userstag::where('user_id', '=', $user_id)->delete();
foreach ($result->skills->values as $key => $item) {
$tag = new Tag();
$Tag = tag::firstOrCreate(array('name' => $item->skill->name));
$tag_id = $Tag['id'];
$users_tag = new Userstag();
$users_tag->user_id = $user_id;
$users_tag->tag_id = $tag_id;
$users_tag->save();
}
return true;
}
} else {
if (!empty($result['skills']['values'])) {
foreach ($result['skills']['values'] as $key => $item) {
$tag = new Tag();
$Tag = tag::firstOrCreate(array('name' => $item['skill']['name']));
$tag_id = $Tag['id'];
$users_tag = new Userstag();
$users_tag->user_id = $user_id;
$users_tag->tag_id = $tag_id;
$users_tag->save();
}
return true;
}
}
return true;
//echo "<pre>"; print_r($result); echo "</pre>";die();
}