Closed Matslom closed 8 years ago
I wanted also add timestamps on creating user. After disabling them in model, there is no way to use with create method.
Can we use something like this
UserRepository.php
$user = new $this->userModel; $user->name = $details['name']; $user->email = $details['email']; ... $user->timestamps = true; $user->save();
instead of this
$this->userModel->create($details)
?
That slight work, or you could set time stamps before create, then reset it.
On 27 Jun 2016, at 21:32, Matslom notifications@github.com wrote:
I wanted also add timestamps on creating user. After disabling them in model, there is no way to use with create method. Can we use something like this UserRepository.php $user = new $this->userModel; $user->name = $details['name']; $user->email = $details['email']; ... $user->timestamps = true; $user->save();
instead of this $this->userModel->create($details)?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
My thought would be
public function create(array $details)
{
// manually set timestamps after creating the model
$user = $this->userModel->create($details);
$user->touch();
return $user;
}
I would think that would work, but I have yet to test it. $timestamps should only affect whether or not Eloquent tries to automatically update timestamps. This should manually do so.
Unfortunately, not really
public function touch()
{
if (! $this->timestamps) {
return false;
}
Well... That's unfortunate. Try...
public function create(array $details)
{
// manually set timestamps after creating the model
$user = $this->userModel->create($details);
return $user->setCreatedAt($user->getFreshTimestamp())
->setUpdatedAt($user->getFreshTimestamp());
}
That should do things in an acceptable way and return the model (at least according to the API docs)
Yep, it works
$user->setCreatedAt($user->freshTimestamp())
->setUpdatedAt($user->freshTimestamp())->save();
Also, it looks like you're using tabs. We're not using tabs anymore as of today, so if you could switch to 4 spaces per "tab", that would be great. Otherwise the code sniffer on Travis CI will freak out when we get this PR to go to it. To see if stuff is formatted correctly, you can run composer sniff
.
:smile: I used 4 spaces in first commit. No problem, I will change it.
Sorry! We passed an internal RFC recently to change the standards to be plain PSR-2 with the prefix/suffix requirements added on!
Couple of small comments there, the style checks can be ignored for now.