本文整理汇总了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;
}
示例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');
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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));
}
示例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);
}
}
示例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));
}
}
示例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;
}
示例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'));
}
示例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);
}
示例13: getPost
public function getPost(Request $request)
{
return Posts::find($request->id);
}
示例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);
}
示例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);
}