本文整理汇总了PHP中app\models\Post::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::where方法的具体用法?PHP Post::where怎么用?PHP Post::where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Post
的用法示例。
在下文中一共展示了Post::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
public function upload()
{
$uploader_id = Auth::user()->active_contact->id;
if (Input::file('file')->isValid()) {
if (Input::get('target') == "posts") {
if (Input::get('target_action') == "create") {
$target = Post::where('author_id', $uploader_id)->where("status_id", "=", POST_DRAFT_STATUS_ID)->where("ticket_id", Input::get('target_id'))->first();
} elseif (Input::get('target_action') == "edit") {
$target = Post::where("id", Input::get('target_id'))->first();
}
} elseif (Input::get('target') == "tickets") {
if (Input::get('target_action') == "create") {
$target = Ticket::where('status_id', TICKET_DRAFT_STATUS_ID)->where('creator_id', $uploader_id)->first();
} elseif (Input::get('target_action') == "edit") {
$target = Ticket::where("id", Input::get('target_id'))->first();
}
}
$id = $target->id;
$request['target_id'] = $id;
$request['uploader_id'] = $uploader_id;
$request['file'] = Input::file('file');
$request['target'] = Input::get('target');
$request['target_action'] = Input::get('target_action');
$response = $this->repo->upload($request);
$response = Response::json($response, 200);
return $response;
}
}
示例2: getPosts
public static function getPosts($post_id)
{
$photo_id = Post::where('post_id', $post_id)->get(['photo_link'])[0]["photo_link"];
$list_id = PostRecommendView::where("photo_id", $photo_id)->orderBy("rank", "desc")->take(10)->get(["post_id_recommend"]);
$results = UserPosts::whereIn("post_id", $list_id)->distinct('photo_link')->get();
return $results;
}
示例3: store
/**
* Store a newly created Comment in storage.
* POST /comments
*
* @param Request $request
*
* @return Response
*/
public function store(Request $request)
{
if (sizeof(Comment::$rules) > 0) {
$validator = $this->validateRequestOrFail($request, Comment::$rules);
if ($validator) {
return $validator;
}
}
$input = $request->all();
$input['objectId'] = str_random(10);
$comments = $this->commentRepository->create($input);
if (isset($input['postType']) && $input['postType'] == 'iWomenPost') {
$post = IwomenPost::where('objectId', $input['postId'])->first();
if ($post) {
$post->comment_count = $post->comment_count + 1;
$post->update();
}
} else {
if (isset($input['postType']) && $input['postType'] == 'Post') {
$post = Post::where('objectId', $input['postId'])->first();
if ($post) {
$post->comment_count = $post->comment_count + 1;
$post->update();
}
} else {
if (isset($input['postType']) && $input['postType'] == 'SubResourceDetail') {
$post = SubResourceDetail::where('objectId', $input['postId'])->first();
if ($post) {
$post->comment_count = $post->comment_count + 1;
$post->update();
}
} else {
if (isset($input['postType']) && $input['postType'] == 'Resources') {
$post = Resources::where('objectId', $input['postId'])->first();
if ($post) {
$post->comment_count = $post->comment_count + 1;
$post->update();
}
}
}
}
}
if (isset($input['postType']) && $input['postType'] == 'Post' || isset($input['postType']) && $input['postType'] == 'SubResourceDetail' || isset($input['postType']) && $input['postType'] == 'Resources') {
if (isset($post) && $post) {
$device_list = [];
$gcm = Gcm::where('user_id', $post->userId)->first();
if ($gcm) {
$device_list[] = PushNotification::Device($gcm->reg_id);
$message['title'] = 'New Comment';
$message['message'] = $comments->comment_contents;
$devices = PushNotification::DeviceCollection($device_list);
$message = PushNotification::Message(json_encode($message), array());
$collection = PushNotification::app('appNameAndroid')->to($devices)->send($message);
}
}
}
$comments['comment_count'] = $post->comment_count;
return $this->sendResponse($comments->toArray(), "Comment saved successfully");
}
示例4: getBoardById
public static function getBoardById($board_id)
{
$result["board"] = Board::where('board_id', $board_id)->first();
$result["posts"] = UserPosts::where('board_id', $board_id)->get();
$result["board"]["cover_link"] = $result["posts"][0]["photo_link"];
$result["profile"]["number_of_posts"] = Post::where('board_id', $board_id)->count();
$result["profile"]["number_of_following"] = FollowEvent::countFollower($board_id);
return $result;
}
示例5: getPreviewBoard
public static function getPreviewBoard($board_id)
{
$list = new \SplFixedArray(4);
$posts = Post::where('board_id', $board_id)->take(4)->get(['photo_link']);
for ($i = 0; $i < count($posts); $i++) {
$list[$i] = url('api/photo' . '/' . $posts[$i]['photo_link']);
}
return $list;
}
示例6: tagIndexData
/**
* Return data for a tag index page
*
* @param string $tag
* @return array
*/
protected function tagIndexData($tag)
{
$tag = Tag::where('tag', $tag)->firstOrFail();
$reverse_direction = (bool) $tag->reverse_direction;
$posts = Post::where('published_at', '<=', Carbon::now())->whereHas('tags', function ($q) use($tag) {
$q->where('tag', '=', $tag->tag);
})->where('is_draft', 0)->orderBy('published_at', $reverse_direction ? 'asc' : 'desc')->simplePaginate(config('upload.posts_per_page'));
$posts->addQuery('tag', $tag->tag);
$page_image = $tag->page_image ?: config('upload.page_image');
return ['title' => $tag->title, 'subtitle' => $tag->subtitle, 'posts' => $posts, 'page_image' => $page_image, 'tag' => $tag, 'reverse_direction' => $reverse_direction, 'meta_description' => $tag->meta_description ?: config('upload.description')];
}
示例7: search
public function search(Request $request)
{
$search = $request->keywords ? $request->keywords : '';
$offset = $request->page ? $request->page : 1;
$limit = $request->limit ? $request->limit : 12;
$isAllow = $request->isAllow ? $request->isAllow : 1;
$category = $request->category;
$offset = ($offset - 1) * $limit;
$posts = Post::where('title', 'like', '%' . $search . '%')->orwhere('titleMm', 'like', '%' . $search . '%')->orwhere('content', 'like', '%' . $search . '%')->orwhere('content_mm', 'like', '%' . $search . '%')->orwhere('postUploadName', 'like', '%' . $search . '%')->where('isAllow', $isAllow)->where('category_id', $category)->orderBy('postUploadedDate', 'desc')->offset($offset)->limit($limit)->get();
return response()->json($posts);
}
示例8: authorize
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
if (!parent::authorize()) {
return false;
}
if ($this->blog) {
if ($this->user()->isAdmin()) {
return true;
}
return Post::where('id', $this->blog)->where('user_id', $this->user()->id)->exists();
}
return true;
}
示例9: show
public function show($id)
{
if (Auth::user()->can('read-ticket')) {
$data['ticket'] = self::API()->find(['id' => $id]);
if ($data['ticket']) {
$data['title'] = "Ticket #" . $data['ticket']->id;
$data['menu_actions'] = [Form::editItem(route('tickets.edit', $id), "Edit This Ticket", Auth::user()->can('update-ticket'))];
$data['ticket']['posts'] = PostsController::API()->all(['where' => ['ticket_id|=|' . $id], "order" => ['posts.created_at|ASC'], "paginate" => "false"]);
$data['ticket']['history'] = TicketHistory::where('ticket_id', '=', $id)->orderBy('created_at')->get();
$data['statuses'] = Status::where('id', TICKET_WFF_STATUS_ID)->orWhere('id', TICKET_SOLVED_STATUS_ID)->get();
$data['draft_post'] = Post::where("ticket_id", $id)->where("status_id", POST_DRAFT_STATUS_ID)->where("author_id", Auth::user()->active_contact->id)->first();
$data['important_post'] = null;
if (in_array($data['ticket']->status_id, [TICKET_SOLVED_STATUS_ID, TICKET_WFF_STATUS_ID])) {
foreach ($data['ticket']['posts']->reverse() as $post) {
if ($post->ticket_status_id != $data['ticket']->status_id) {
break;
} else {
$data['important_post'] = $post;
}
}
}
$links = [];
$temp = TicketLink::where("ticket_id", "=", $id)->get();
foreach ($temp as $elem) {
$links[] = $elem->linked_ticket_id;
}
$data['ticket']['links'] = self::API()->all(['where' => ['tickets.id|IN|' . implode(":", $links)]]);
$linked_to = [];
$temp = TicketLink::where("linked_ticket_id", "=", $id)->get();
foreach ($temp as $elem) {
$linked_to[] = $elem->ticket_id;
}
$data['ticket']['linked_to'] = self::API()->all(['where' => ['tickets.id|IN|' . implode(":", $linked_to)]]);
if (isset($data['important_post'])) {
switch ($data['ticket']->status_id) {
case TICKET_WFF_STATUS_ID:
$data['important_post']->alert_type = "danger";
break;
case TICKET_SOLVED_STATUS_ID:
$data['important_post']->alert_type = "success";
break;
}
}
return view('tickets/show', $data);
} else {
return redirect()->back()->withErrors(['404 The following Ticket coudn\'t be found']);
}
} else {
return redirect()->back()->withErrors(['Access denied to tickets show page']);
}
}
示例10: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$post = Post::with(array('User' => function ($query) {
$query->select('id', 'name');
}))->find($id);
if (!$post) {
return Response::json(['error' => ['message' => 'Post does not exist']], 404);
}
// get previous joke id
$previous = Post::where('id', '<', $post->id)->max('id');
// get next joke id
$next = Post::where('id', '>', $post->id)->min('id');
return Response::json(['previous_joke_id' => $previous, 'next_joke_id' => $next, 'data' => $this->transform($post)], 200);
}
示例11: add
public static function add($data)
{
try {
$post = Post::where('code', '=', $data['code'])->first();
if (is_null($post)) {
$post = Post::create(array('name' => $data['name'], 'code' => $data['code'], 'public_date' => date('Y-m-d H:i:s'), 'preview_text' => Purifier::clean($data['preview_text']), 'text' => Purifier::clean($data['text']), 'user_id' => Auth::user()->id));
} else {
return false;
}
} catch (Exception $e) {
Log::info('Post:add(): ' . $e->getMessage());
return false;
}
return $post;
}
示例12: store
public function store(CreatePostRequest $request)
{
$draft = $draft = Post::where('author_id', Auth::user()->active_contact->id)->where("status_id", "=", POST_DRAFT_STATUS_ID)->where("ticket_id", $request->get("ticket_id"))->first();
$post = $draft ? $draft : new Post();
$post->ticket_id = $request->get('ticket_id');
$post->post = $request->get('post');
$post->author_id = Auth::user()->active_contact->id;
$post->status_id = $request->get('is_public') ? POST_PUBLIC_STATUS_ID : POST_PRIVATE_STATUS_ID;
$post->ticket_status_id = $request->get('status_id');
if (isset($post->updated_at)) {
$post->created_at = $post->updated_at;
}
$post->save();
$ticket_updated = $this->updateTicket($request);
EmailsManager::sendPost($post->id, $ticket_updated, $request->get('emails'));
SlackManager::sendPost($post, $ticket_updated);
return redirect()->route('tickets.show', $request->input('ticket_id'))->with('successes', ['Post created successfully']);
}
示例13: setRecommend
public static function setRecommend()
{
$user_id = Auth::user()->user_id;
$list_post = Post::where("user_id", '!=', $user_id)->get();
foreach ($list_post as $post) {
// $list_id = (array) DB::select(DB::raw("SELECT * FROM user_posts WHERE user_id != ".$user_id." ORDER BY RAND() LIMIT 10"));
$list_id = Post::where("user_id", "!=", $user_id)->orderByRaw("rand()")->distinct('photo_link')->take(5)->get();
foreach ($list_id as $id) {
$recommend = new PostRecommend();
$recommend->photo_id = $post["photo_link"];
$recommend->photo_id_recommend = $id["photo_link"];
$recommend->rank = 1.0;
$recommend->save();
}
// print_r($post);
}
return $list_id;
}
示例14: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$author = User::whereHas('role', function ($q) {
$q->where('slug', 'admin');
})->first();
$categories = Category::where('is_active', 1)->get();
$postsRecents = Post::where('is_active', 1)->where('seen', 1)->orderBy('created_at', 'desc')->take(3)->get();
$postsPopular = Post::where('is_active', 1)->where('seen', 1)->orderBy('nview', 'desc')->take(3)->get();
$commentsRecents = Comment::where('seen', 1)->orderBy('created_at', 'desc')->take(3)->get();
$tags = Tag::all();
$INFO_SITE = Admin::first();
view()->share('author', $author);
view()->share('categories', $categories);
view()->share('tags', $tags);
view()->share('postsRecents', $postsRecents);
view()->share('postsPopular', $postsPopular);
view()->share('commentsRecents', $commentsRecents);
view()->share('INFO_SITE', $INFO_SITE);
}
示例15: getIsAdmin
/**
* دریافت پست بر اساس ایدی و در صورتیکه درخواست کننده ادمین باشد
* و دسترسی به هر نوع پست غیرفعال نیز دارد
*
* @param int $pst_id
* @return Illuminate\Support\Collection
*/
public function getIsAdmin($pst_id)
{
$Res = $this->model->where('pst_id', "{$pst_id}")->first();
$this->AddJalaliDate($Res, " ", false);
return $Res;
}