本文整理汇总了PHP中app\Post::whereRaw方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::whereRaw方法的具体用法?PHP Post::whereRaw怎么用?PHP Post::whereRaw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::whereRaw方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMore
public function getMore($excludes)
{
$excludes = explode("SEPARATOR", $excludes);
$whereString = "";
foreach ($excludes as $exclude) {
$whereString = $whereString . "slug != ? AND ";
}
$whereString = substr($whereString, 0, -5);
$posts = Post::whereRaw($whereString, $excludes)->take(3)->orderBy("created_at", "desc")->get();
return view("posts.ajax")->with("posts", $posts);
}
示例2: postsList
public function postsList($nodeId = '')
{
$nodeIds = DB::table('node_hierarchy')->where('node_parent_id', '=', $nodeId)->lists('node_id');
$nodeIds = array_merge($nodeIds, [$nodeId]);
$nodeIds = implode(',', $nodeIds);
// if($nodeId==''){
// $posts = Post::paginate(10);
// $node = '';
// }else{
$posts = Post::whereRaw("node_id in ({$nodeIds})")->orderBy('created_at', 'DESC')->paginate(6);
$node = Node::find($nodeId);
// }
//dd(response()->json(view('home.post.posts',compact('posts'))->render()));
if (Request::ajax()) {
return response()->json(view('home.post.posts', compact('posts'))->render());
}
return view('home.post.index', compact('posts', 'node'));
}
示例3: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
# Share variable cross views
if (Schema::hasTable('posts')) {
$totalnewposts = Post::whereRaw('DATE(created_at) >= DATE_SUB(NOW(),INTERVAL 30 DAY)')->count();
} else {
$totalnewposts = 0;
}
# Get all backgrounds filenames in an array
# For random Background $backgrounds->random()
$backgrounds = collect(Storage::disk('backgrounds')->allFiles());
view()->share(['totalnewposts' => $totalnewposts, 'backgrounds' => $backgrounds]);
Validator::extend('farsi', function ($attribute, $value, $parameters) {
return preg_match('/^[اآإأبپتثجچحخدذرزژسشصضظطعغفقکگلمنوؤهةۀیئيءـًٌٍَُِِّ\\s]+$/', $value);
});
Blade::extend(function ($value) {
return preg_replace('/\\@define(.+)/', '<?php ${1}; ?>', $value);
});
}
示例4: show
/**
* @param $pid
* @return \Response
*/
public function show($pid)
{
if (empty($pid) || is_null($pid)) {
abort(404);
}
$post = Post::findOrFail($pid);
$prevPost = Post::whereRaw('id = (select max(id) from posts where id < ' . $pid . ')')->limit(1)->orderBy('id', 'asc')->first();
$nextPost = Post::whereRaw('id = (select min(id) from posts where id > ' . $pid . ')')->limit(1)->orderBy('id', 'asc')->first();
$data = ['post' => $post, 'photos' => [], 'videos' => [], 'links' => [], 'audios' => [], 'polls' => [], 'prevPostUrl' => is_null($prevPost) ? null : route('post_show', ['pid' => $prevPost->id]), 'nextPostUrl' => is_null($nextPost) ? null : route('post_show', ['pid' => $nextPost->id])];
if (!is_null($post->attachments)) {
foreach ($post->attachments as $attachment) {
if ($attachment->type === 'album') {
$photos = $attachment->childs;
foreach ($photos as $photo) {
array_push($data['photos'], $photo);
}
continue;
}
array_push($data[$attachment->type . 's'], $attachment);
}
}
return view('post.post', $data);
}
示例5: slug
/**
* just a small API request to find the next slug
* @param Request $request [description]
* @return [type] [description]
*/
public function slug(Request $request)
{
if (!$request->has('slug')) {
return response()->json(['valid' => false, 'slug' => '']);
}
// generate the default slug
$slug = str_slug($request->input('slug'));
// check to see if one already exists
$lastSlug = Post::whereRaw("slug RLIKE '^" . $slug . "(-[0-9]*)?\$'")->latest('created_at')->value('slug');
if ($lastSlug) {
// explode the parts
$parts = explode('-', $lastSlug);
$number = end($parts);
$slug .= '-' . ($number + 1);
}
return response()->json(['valid' => true, 'slug' => $slug]);
}
示例6: filterCategory
public function filterCategory(Request $request)
{
$posts = \App\Post::whereRaw('published_at <= ? and category_id = ?', array(Carbon::now(), $request->input("category")->value))->paginate(config('blog.posts_per_page'));
return view('blog.index', compact('posts'));
}