本文整理汇总了PHP中app\Post::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::where方法的具体用法?PHP Post::where怎么用?PHP Post::where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post_all
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function post_all(Request $request)
{
$user = $request->user();
$posts = Post::where('author_id', $user->id)->orderBy('created_at', 'desc')->paginate(10);
$title = $user->name;
return view('frontend.post.show')->withPosts($posts)->withTitle($title);
}
示例2: show
/**
* Shows the specific user.
* @param string $username
* @return Response
*/
public function show($username)
{
$post_upvotes = 0;
$user = User::where('username', '=', $username)->firstOrFail();
$user_posts = Post::where('user_id', '=', $user->id)->take(3)->get();
foreach ($user_posts as $post) {
$post->username = $user->username;
$post->comment_count = Comment::where('post_id', '=', $post->id)->count();
$post->hub_name = Hub::where('id', '=', $post->hub_id)->firstOrFail()->name;
$post_upvotes = $post_upvotes + (int) $post->upvotes;
$hub = Hub::find($post->hub_id);
if (in_array($post->user_id, explode(',', $hub->moderators))) {
$post->user_is_mod = true;
} else {
$post->user_is_mod = false;
}
$user = User::find($post->user_id);
if ($user->is_admin) {
$post->user_is_admin = true;
} else {
$post->user_is_admin = false;
}
}
$comment_upvotes = 0;
$user_comments = Comment::where('user_id', '=', $user->id)->take(3)->get();
foreach ($user_comments as $comment) {
$comment_upvotes = $comment_upvotes + (int) $comment->upvotes;
$comment->email = md5($user->email);
}
return view('user.show', ['user' => $user, 'email' => md5($user->email), 'post_upvotes' => $post_upvotes, 'comment_upvotes' => $comment_upvotes, 'comments' => $user_comments, 'posts' => $user_posts]);
}
示例3: getFeed
public function getFeed($type = null)
{
$feed = App::make('feed');
//$feed->setCache(60);
$parsedown = new Parsedown();
$parsedown->setMarkupEscaped(true);
if (!is_null($type)) {
$posts = Post::where('feed', $type)->with('user')->orderBy('created_at', 'desc')->take(20)->get();
} else {
$posts = Post::with('user')->orderBy('created_at', 'desc')->take(20)->get();
}
$pubDate = count($posts) == 0 ? date('Y-m-d H:i:s') : $posts[0]->created_at;
$feed->title = 'rhofma.de - Blog';
$feed->description = 'Web-Developer Blog';
$feed->logo = asset('img/logo.svg');
$feed->link = URL::to('/');
$feed->setDateFormat('datetime');
$feed->pubdate = $pubDate;
$feed->lang = 'de';
$feed->setShortening(true);
$feed->setTextLimit(500);
foreach ($posts as $post) {
$feed->add($post->title, $post->user->name, URL::to($post->slug), $post->created_at, $text = $post->teaser, $parsedown->parse($post->content));
}
return $feed;
}
示例4: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('posts', function (Blueprint $table) {
$table->boolean('body_rtl')->nullable()->default(null)->after('body_html');
});
Post::where(DB::raw('1=1'))->update(['body_parsed' => null, 'body_parsed_at' => null, 'body_html' => null]);
}
示例5: getShowPost
/**
* Show post action, show one post. Search by slug first,
* and if no result, search by id
*
* @param $id
* @return \Illuminate\View\View
*/
public function getShowPost($id)
{
if (!($post = Post::where('slug', $id)->first())) {
$post = Post::find((int) $id);
}
return view('front.showPost', compact('post'));
}
示例6: showBoutiquePosts
public function showBoutiquePosts($user_id)
{
$user = $this->userRepository->getById($user_id);
$posts = Post::where('user_id', '=', $user_id)->paginate($this->nbrPerPage);
$links = str_replace('/?', '?', $posts->render());
return view('manager.users.userPostList', compact('posts', 'user', 'links'));
}
示例7: index
public function index()
{
$postType = '精選文章';
$posts = \App\Post::where('is_feature', 1)->orderBy('created_at', 'desc')->paginate(5);
$data = compact('postType', 'posts');
return view('posts.index', $data);
}
示例8: index
/**
* Show the application dashboard to the user.
*
* @return Response
*/
public function index()
{
$posts = \App\Post::where('is_hot', true)->orderBy('created_at', 'desc')->paginate(5);
$post_type = '熱門文章';
$data = compact('posts', 'post_type');
return view('posts.index', $data);
}
示例9: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$recipies = Post::where('postStatus_id', '=', 3)->get();
Session::put('recipies', $recipies);
$title = CmsOption::getValue('Название сайта');
return view('home', ['recipies' => $recipies, 'title' => $title]);
}
示例10: edit
public function edit(Request $request, $id)
{
$post = Post::where('id', $id)->first();
if ($post && $request->user()->id == $post->user_id) {
return view('/edit')->with('post', $post);
}
}
示例11: showProfile
/**
* Show the application dashboard to the user.
*
* @return Response
*/
public function showProfile($id)
{
$user = User::find($id);
$posts = Post::where("user_id", $id)->get();
$comments = Comment::where('user_id', $id)->get();
return view('user.profile', ['user' => $user, 'comments' => $comments, 'posts' => $posts]);
}
示例12: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$is_student = Auth::user()->is_student;
$color = $is_student ? '#3498db' : '#e74c3c';
if ($is_student) {
logger("学生アカウントナリ");
$user = UserProfile::where('student_id', '=', Auth::user()->id)->first();
if ($user === null) {
// 学生用ページを表示
$tech_items = ['Java' => 0, 'C' => 0, 'C++' => 0, 'Python' => 0, 'C#' => 0, 'Objective-C' => 0, 'Perl' => 0, 'HTML' => 0, 'CSS' => 0, 'JavaScript' => 0, 'PHP' => 0, 'Ruby' => 0, 'Scala' => 0];
$tech = json_encode($tech_items);
$user = ["name" => "", "student_id" => Auth::user()->id, "gender" => "", "birth" => "", "address" => "", "phone_number" => "", "collage" => "", "collage_type" => "", "github" => "", "intern" => "", "hackathon" => "", "work" => "", "tech" => $tech];
UserProfile::create($user);
}
$data = ['名前' => Auth::user()->name, '性別' => $user['gender'] === "man" ? "男" : "女", '誕生日' => $user['birth'], '住所' => $user['address'], "メールアドレス" => Auth::user()->email, '電話番号' => $user['phone_number'], '大学名' => $user['collage'], '学部' => $user['collage_type'], 'Github' => $user['github']];
$tech = json_decode($user['tech'], true);
$award = ['インターン' => $user['intern'], 'ハッカソン' => $user['hackathon'], '仕事' => $user['work']];
return view('mypage', ["datas" => $data, "color" => $color, "awards" => $award, "tech" => $tech]);
} else {
logger("企業アカウントナリ");
// 企業用ページを表示
$profile = CompanyProfile::where('company_id', '=', Auth::user()->id)->first();
logger($profile);
if ($profile === null) {
logger("新規作成するナリ");
$profile = ['name' => "", 'company_id' => Auth::user()->id, 'phone_number' => "", 'email' => "", 'homepage' => ""];
CompanyProfile::create($profile);
}
$works = Post::where('company_id', '=', Auth::user()->id)->get();
logger($profile);
return view('mypage_company', ['profile' => $profile, 'works' => $works, 'color' => $color]);
}
}
示例13: user_posts_draft
public function user_posts_draft(Request $request)
{
$user = $request->user();
$posts = Post::where('author_id', $user->id)->where('active', 0)->orderBy('created_at', 'desc')->paginate(5);
$title = $user->name;
return view('home')->withPosts($posts)->withTitle($title);
}
示例14: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($slug)
{
$post = Post::where('slug', $slug)->firstOrFail();
$moreWorks = Work::orderByRaw('RAND()')->take(3)->get();
$morePosts = Post::where('slug', '!=', $post->slug)->orderByRaw('RAND()')->take(3)->get();
return view('posts.show', compact("post", "moreWorks", "morePosts"));
}
示例15: showPost
/**
* @param $id
* @param $slug
* @return the view of the active post
*/
public function showPost($id, $slug)
{
if (!($post = Post::where('slug', $id)->first())) {
$post = Post::find((int) $id);
}
return view('front.blog.single', compact('post'));
}