本文整理汇总了PHP中app\Profile::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Profile::firstOrNew方法的具体用法?PHP Profile::firstOrNew怎么用?PHP Profile::firstOrNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Profile
的用法示例。
在下文中一共展示了Profile::firstOrNew方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created profile in storage.
*
* @return Response
*/
public function store(CreateProfileRequest $request)
{
$profile = Profile::firstOrNew(['user_id' => \Auth::id()]);
if ($request->id) {
$placeliving = Place::where('id', '=', $request->id)->first();
if (!$placeliving) {
$placeliving = new Place($request->only(['id', 'place_lat', 'place_lng', 'country', 'state', 'city']));
$placeliving->save();
}
$profile->place_living_id = $request->id;
}
if ($request->id2) {
$placefrom = Place::where('id', '=', $request->id2)->first();
if (!$placefrom) {
$placefrom = new Place();
$placefrom->id = $request->id2;
$placefrom->place_lat = $request->place_lat2;
$placefrom->place_lng = $request->place_lng2;
$placefrom->country = $request->country2;
$placefrom->state = $request->state2;
$placefrom->city = $request->city2;
$placefrom->save();
}
$profile->place_from_id = $request->id2;
}
if ($request->about) {
$profile->about = $request->about;
}
if ($request->occupation) {
$profile->occupation = $request->occupation;
}
if ($request->studies) {
$profile->studies = $request->studies;
}
if ($request->transport) {
$profile->transport = $request->transport;
}
$profile->save();
\Session::flash('message', 'Profile updated successfully');
return redirect()->route('index');
}
示例2: normalize
/**
* @param $reviewData
* @return \App\Review
*/
public static function normalize(&$reviewData)
{
$review = ReviewModel::firstOrNew(['external_id' => $reviewData['id']]);
$review->external_id = $reviewData['id'];
$review->text = $reviewData['text'];
$review->date = Carbon::createFromTimestamp($reviewData['date']);
$profileData = $reviewData['profile'];
$profile = ProfileModel::firstOrNew(['external_id' => $reviewData['profile']['uid']]);
$profile->first_name = $profileData['first_name'];
$profile->last_name = $profileData['last_name'];
$profile->domain = $profileData['domain'];
if (isset($profileData['photo_200_orig'])) {
$profile->photo = $profileData['photo_200_orig'];
}
if (isset($profileData['photo_400_orig'])) {
$profile->photo_big = $profileData['photo_400_orig'];
}
$profile->save();
$profile->reviews()->save($review);
return $review;
}