本文整理汇总了PHP中State::whereRaw方法的典型用法代码示例。如果您正苦于以下问题:PHP State::whereRaw方法的具体用法?PHP State::whereRaw怎么用?PHP State::whereRaw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类State
的用法示例。
在下文中一共展示了State::whereRaw方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: unlike
public function unlike($type, $id)
{
$type = $this->str($type);
$user = Auth::user();
$like = $this->get($type, $id, $user->id);
if ($like) {
if ($like->delete()) {
$object = strtolower($type);
State::whereRaw('object=? and object_id=? and event=\'liked\'', array($object, $id))->delete();
Notification::whereRaw('object=? and object_id=? and event=\'liked\'', array($object, $id))->get()->each(function ($notification) use($user) {
NotificationUser::whereRaw('notification_id=? and user_id=?', array($notification->id, $user->id))->get()->each(function ($notificationsUser) {
$notificationsUser->is_removed = 1;
$notificationsUser->save();
});
$notification->is_removed = 1;
$notification->save();
});
Notification::whereRaw('object=? and event=\'liked\' and is_removed=0 and ' . '(select count(nu.id) from notifications_users nu where nu.notification_id=notifications.id and nu.is_removed=0)=0', array($object))->get()->each(function ($notification) {
$notification->is_removed = 1;
$notification->save();
});
return $this->respondNoContent();
}
} else {
return $this->respondNotFound('Like not found');
}
return $this->respondServerError();
}
示例2: getUserStates
private function getUserStates($userId)
{
$states = array();
State::whereRaw('owner_id = ?', array($userId))->orderBy('timestamp', 'asc')->get()->each(function ($state) use(&$states) {
$states[] = $state;
});
return $states;
}
示例3: destroy
/**
* Remove the specified resource from storage.
* DELETE /comments/{id}
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$validator = $this->validateId($id);
if ($validator->fails()) {
return $this->respondInsufficientPrivileges($validator->messages()->all());
}
$comment = Comment::find($id);
if ($comment) {
$post = $comment->post;
$category = $post->category;
if ($comment->delete()) {
State::whereRaw('object=\'comment\' and object_id=?', array($id))->delete();
NotificationUser::whereRaw('subject=\'comment\' and subject_id=? and is_removed=0', array($id))->get()->each(function ($notificationsUser) {
$notificationsUser->is_removed = 1;
$notificationsUser->save();
});
Notification::whereRaw('object=\'post\' and event=\'commented\' and is_removed=0 and ' . '(select count(nu.id) from notifications_users nu where nu.notification_id=notifications.id and nu.is_removed=0)=0')->get()->each(function ($notification) {
$notification->is_removed = 1;
$notification->save();
});
return $this->respondNoContent();
}
} else {
return $this->respondNotFound('Comment not found');
}
return $this->respondServerError();
}
示例4: destroy
/**
* Remove the specified resource from storage.
* DELETE /posts/{id}
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$post = Post::find($id);
if (!$post) {
return $this->respondNotFound();
}
$user = Auth::user();
if (!$user->can('Post.delete', $post)) {
return $this->respondInsufficientPrivileges();
}
if ($post->delete()) {
$category = $post->category;
$category->updateCount('posts');
$commentsIds = array();
Comment::where('post_id', $id)->get()->each(function ($comment) use($commentsIds) {
$commentsIds[] = $comment->id;
});
if (count($commentsIds) > 0) {
State::whereRaw('object=\'comment\'')->whereIn('object_id', $commentsIds)->delete();
}
$post->comments()->delete();
$category->updateCount('comments');
State::whereRaw('object=\'post\' and object_id=?', array($id))->delete();
Notification::whereRaw('object=\'post\' and object_id=? and is_removed=0', array($id))->get()->each(function ($notification) {
NotificationUser::where('notification_id', $notification->id)->get()->each(function ($notificationsUser) {
$notificationsUser->is_removed = 1;
$notificationsUser->save();
});
$notification->is_removed = 1;
$notification->save();
});
return $this->respondNoContent();
}
return $this->respondServerError();
}