本文整理汇总了PHP中app\Address::retrieveOrCreate方法的典型用法代码示例。如果您正苦于以下问题:PHP Address::retrieveOrCreate方法的具体用法?PHP Address::retrieveOrCreate怎么用?PHP Address::retrieveOrCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Address
的用法示例。
在下文中一共展示了Address::retrieveOrCreate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateAndSaveConsumer
private function validateAndSaveConsumer(Request $request, Consumer $consumer)
{
$this->validate($request, array_merge(['first_name' => 'required', 'last_name' => 'required', 'description' => 'required'], Address::rules()));
// TODO: check to see if logged in user is a caregiver for this consumer
$consumer->first_name = $request->first_name;
$consumer->last_name = $request->last_name;
$consumer->description = $request->description;
$consumer->address_id = Address::retrieveOrCreate(['street' => $request->street, 'city' => $request->city, 'state' => $request->state, 'zip1' => $request->zip1])->id;
$consumer->save();
return Redirect::to('/caregiver');
}
示例2: postUpdate
/**
* update the given user's profile info.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function postUpdate(Request $request)
{
$this->validate($request, ['id' => 'required|exists:users']);
$user = User::find($request->id);
$user->email = $request->email;
$this->validate($request, array_merge(['id' => 'required|exists:users', 'email' => 'email|max:255' . ($user->isDirty('email') ? '|unique:users,email' : '')], Address::rules()));
if (Auth::user()->id != $request->id && !Auth::user()->administrator) {
//todo: access denied (handle w/ middleware instead of controller?)
} else {
$user->first_name = $request->first_name;
$user->last_name = $request->last_name;
$user->address_id = Address::retrieveOrCreate(['street' => $request->street, 'city' => $request->city, 'state' => $request->state, 'zip1' => $request->zip1])->id;
$user->save();
return Redirect::to('/profile/' . $request->id);
}
}
示例3: create
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
$address = Address::retrieveOrCreate(['street' => $data['street'], 'city' => $data['city'], 'state' => $data['state'], 'zip1' => $data['zip1']]);
return User::create(['address_id' => $address->id, 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
}