本文整理汇总了PHP中app\Post::Where方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::Where方法的具体用法?PHP Post::Where怎么用?PHP Post::Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::Where方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: status
public function status($id)
{
$post = Post::where('id', $id)->first();
if ($post['post_status'] == '0') {
Post::Where('id', $id)->update(['post_status' => '1']);
$status = 'active';
} elseif ($post['post_status'] == '1') {
Post::Where('id', $id)->update(['post_status' => '0']);
$status = 'inactive';
} else {
return Response::json(['status' => 'error']);
}
return Response::json(['status' => $status]);
}
示例2: function
Route::get('updateme/{id}', function ($id) {
$response = ['posts' => App\Post::numberOfPostsSinceId($id)];
return response()->json($response);
});
Route::get('dumper', function () {
$getter = new \App\Getters\LebaneseBlogsGetter();
$post = $getter->getList()[0];
$post = (new \App\Transformers\LebaneseBlogsTransformer($post))->get();
return $post;
});
Route::get('/{provider?}', function ($provider = null) {
if ($provider) {
// make sure the provider supported
if (!in_array($provider, ['facebook', 'youtube', 'instagram', 'lebaneseblogs', 'twitter'])) {
return response('page does not exist', 404);
}
// prepare posts. Cache if no cache
$cacheRef = $provider . '__lastFiftyPosts';
if (!\Cache::has($cacheRef)) {
\Cache::put($cacheRef, \App\Post::Where('provider', $provider)->orderBy('date_published', 'DESC')->take(50)->get(), 3);
}
$posts = \Cache::get($cacheRef);
} else {
// prepare posts. Cache if no cache
if (!\Cache::has('lastFiftyPosts')) {
\Cache::put('lastFiftyPosts', \App\Post::orderBy('date_published', 'DESC')->take(50)->get(), 3);
}
$posts = \Cache::get('lastFiftyPosts');
}
return view('layout')->with(['posts' => $posts, 'provider' => $provider]);
});