当前位置: 首页>>代码示例>>PHP>>正文


PHP Posts::find方法代码示例

本文整理汇总了PHP中app\Posts::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Posts::find方法的具体用法?PHP Posts::find怎么用?PHP Posts::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Posts的用法示例。


在下文中一共展示了Posts::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveScore

 public function saveScore(Request $request)
 {
     if (!auth() || !auth()->user()) {
         echo 'Kết quả chưa được lưu.';
         return;
     }
     $UserID = auth()->user()->getAuthIdentifier();
     $data = $request->all();
     $token = $data['token'];
     // day by day, no. of record will increase
     // => maybe there are multiple record with the same value of UserID and token
     // => pick the newest record
     $record = Doexams::where('token', 'LIKE', $token)->where('UserID', '=', $UserID)->get()->last();
     if (count($record->toArray()) < 1) {
         echo 'Kết quả chưa được lưu.';
         return;
     }
     $record->Score = $request['Score'] . '/' . $request['MaxScore'];
     $record->update();
     $oldDateTime = $record->created_at->getTimestamp();
     $newDateTime = $record->updated_at->getTimestamp();
     $diff = ($newDateTime - $oldDateTime) / 3600.0;
     $record->Time = $diff;
     $record->update();
     if ($diff > 0) {
         $course = Courses::find(Posts::find($record->PostID)->CourseID);
         $course->TotalHours += $diff;
         $course->update();
     }
     echo 'Kết quả đã được lưu lại.';
     return;
 }
开发者ID:ngocdon0127,项目名称:e-learning,代码行数:32,代码来源:DoexamsController.php

示例2: deletePost

 public function deletePost($deletePostId)
 {
     $deletePost = Posts::find($deletePostId);
     if ($deletePost->photo != 'noImage.jpg') {
         //delete the image associative with the post
         \File::Delete('img/Post/' . $deletePost->photo);
     }
     $deletePost->delete();
     return redirect('admin');
 }
开发者ID:np-patel,项目名称:exploreTasman,代码行数:10,代码来源:AdminController.php

示例3: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Request $request, $id)
 {
     $comment = Comments::find($id);
     $post = Posts::find($comment->on_post);
     $slug = $post->slug;
     if ($comment && ($comment->from_user == $request->user()->id || $request->user()->is_admin() || $request->user()->is_moderator())) {
         $comment->delete();
         $data['message'] = 'Comment deleted Successfully';
     } else {
         $data['errors'] = 'Invalid Operation. You have not sufficient permissions';
     }
     return redirect('/' . $slug)->with($data);
 }
开发者ID:calimanleontin,项目名称:bet,代码行数:19,代码来源:CommentController.php

示例4: delete

 /**
  * Delete the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function delete($id)
 {
     $post = \App\Posts::find($id);
     $user_id = $post->user()->id;
     $post->delete();
     // Send a message to the user.
     $reason = $_POST['reason'];
     if (isset($_POST['other_reason']) && $_POST['other_reason'] != "") {
         $reason = $_POST['other_reason'];
     } else {
         $reason = $_POST['reason'];
     }
     $message = "Your post has been removed due to the following reason: " . $reason;
     \App\Message::send((int) $_POST['user_id'], 0, "Your post has been removed", $message);
     header('Location:' . url('admin/users/edit/' . $user_id));
     exit;
 }
开发者ID:steakyfask,项目名称:ShareStuff,代码行数:23,代码来源:AdminPostsController.php

示例5: getById

 /**
  * get item by id
  * @param $id
  * @return mixed
  */
 public function getById($id)
 {
     try {
         $statusCode = 200;
         $response = [];
         $post = Posts::find($id);
         if ($post != null) {
             $response['post'] = ['id' => $post->id, 'title' => $post->title, 'description' => $post->description, 'content' => $post->content, 'published' => $post->published];
             $statusCode = 200;
         } else {
             $statusCode = 400;
         }
         $response['status'] = $statusCode;
     } catch (Exeption $e) {
         $statusCode = 400;
     } finally {
         return \Response::json($response, $statusCode);
     }
 }
开发者ID:Hovik123,项目名称:laravel-angularjs,代码行数:24,代码来源:PostController.php

示例6: store

 public function store(Request $request, $id)
 {
     if ($request->ajax()) {
         $post = Posts::find($id);
         $edit_header = $request->input('Header');
         $edit_content = $request->input('Content');
         $v = Validator::make($request->all(), ['Header' => 'required|max:32', 'Content' => 'required']);
         if (!$v->fails()) {
             $post->Header = $edit_header;
             $post->Content = $edit_content;
             if ($post->save()) {
                 $response = array('status' => 'success', 'msg' => 'Setting created successfully');
             } else {
                 $response = array('status' => 'error', 'msg' => 'save failed');
             }
         } else {
             $response = array('status' => 'error', 'msg' => 'v failed');
         }
         return Response::json($response);
     }
 }
开发者ID:austin43,项目名称:personal-site,代码行数:21,代码来源:EditPost.php

示例7: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $question = Questions::find($id);
     @unlink(public_path('images/imageQuestion/' . $question['Photo']));
     $postid = $question['PostID'];
     $format = Posts::find($postid)['FormatID'];
     if ($format == 1) {
         $answers = Answers::where('QuestionID', '=', $id)->get()->toArray();
         foreach ($answers as $answer) {
             Answers::destroy($answer['id']);
         }
     } else {
         if ($format == 2) {
             $spaces = Spaces::where('QuestionID', '=', $id)->get()->toArray();
             foreach ($spaces as $value) {
                 SpacesController::destroy($value['id']);
             }
         }
     }
     $question->delete();
     return redirect(route('user.viewpost', $postid));
 }
开发者ID:kevinhoa95,项目名称:e-learning,代码行数:31,代码来源:QuestionsController.php

示例8: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $data = [];
     $post = Posts::find($id);
     if ($post) {
         if ($post->user_id == $request->user()->id) {
             $post->delete();
         } else {
             // vrakjam 401 unauthorized
             return response()->json([], 401);
         }
     } else {
         // vrakjam 404 not found
         return response()->json([], 404);
     }
 }
开发者ID:1993Dajana,项目名称:pet-care,代码行数:22,代码来源:PostController.php

示例9: komentar

 public function komentar($next)
 {
     if (trim(Input::get('isi')) != "") {
         $komen = new Komentar();
         $komen->idpengguna = Auth::user()->id;
         $komen->idpost = $next;
         $komen->isi = Input::get('isi');
         $komen->save();
         $a = Posts::find($next);
         return redirect(url($a->slug));
     } else {
         return redirect(url($a->slug));
     }
 }
开发者ID:ariefsetya,项目名称:it-club,代码行数:14,代码来源:HomeController.php

示例10: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $post = \App\Posts::find($id);
     $post->delete();
     return $post;
 }
开发者ID:reneedudley,项目名称:bitter,代码行数:12,代码来源:PostsController.php

示例11: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Posts::find($id)->delete();
     return redirect(url('mine/posts'));
 }
开发者ID:ariefsetya,项目名称:it-club,代码行数:11,代码来源:PostController.php

示例12: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Request $request, $id)
 {
     //
     $post = Posts::find($id);
     if ($post && ($post->author_id == $request->user()->id || $request->user()->is_admin())) {
         $post->delete();
         $data['message'] = 'Post deleted Successfully';
     } else {
         $data['errors'] = 'Invalid Operation. You have not sufficient permissions';
     }
     return redirect('/')->with($data);
 }
开发者ID:skakoty,项目名称:JEC-Feedback-Management-System,代码行数:18,代码来源:PostController.php

示例13: getPost

 public function getPost(Request $request)
 {
     return Posts::find($request->id);
 }
开发者ID:shadowfox476,项目名称:hannahs_blog,代码行数:4,代码来源:PostsController.php

示例14: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  Request $request
  * @param int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $post = Posts::find($id);
     if ($post && ($post->author_id == Auth::user()->id || $request->user()->is_admin())) {
         try {
             $post->delete();
             $data = array('alert-type' => 'alert alert-success', 'alert-message' => 'Posten ble slettet!');
         } catch (\Exception $e) {
         }
     } else {
         $data = array('alert-type' => 'alert alert-danger', 'alert-message' => 'Du har ikke tilgang til å slette denne posten!');
     }
     return Redirect::to('/admin/poster/alle')->with($data);
 }
开发者ID:nilsma,项目名称:agtp,代码行数:21,代码来源:PostController.php

示例15: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     //
     $post = Posts::find($id);
     if ($post && ($post->author_id == $request->user()->id || $request->user()->is_admin())) {
         $post->delete();
         $data['message'] = 'Postingan telah di hapus';
     } else {
         $data['errors'] = 'Invalid Operation. Kamu tidak boleh mengakses halaman';
     }
     return redirect('/')->with($data);
 }
开发者ID:dikyarga,项目名称:sistem-informasi-organisasi-dengan-laravel,代码行数:18,代码来源:PostController.php


注:本文中的app\Posts::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。