本文整理汇总了PHP中app\models\Post::query方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::query方法的具体用法?PHP Post::query怎么用?PHP Post::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Post
的用法示例。
在下文中一共展示了Post::query方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index(Request $request)
{
$posts = Post::query()->orderBy('created_at', 'desc')->get()->all();
foreach ($posts as $post) {
$post->author = $post->getAuthor();
}
return view('dashboard.index', ['posts' => $posts]);
}
示例2: findAll
/**
* Get All posts
* @return array
*/
public function findAll($author = null, $from = null, $to = null)
{
$query = Post::query();
if ($author) {
$query = $query->where('author', $author);
}
if ($from) {
$query = $query->whereDate('date', '>=', new DateTime($from));
}
if ($to) {
$query = $query->whereDate('date', '<=', new DateTime($to));
}
return $query->get();
}
示例3: search
public function search($input)
{
$query = Post::query();
$columns = Schema::getColumnListing('posts');
$attributes = array();
foreach ($columns as $attribute) {
if (isset($input[$attribute]) and !empty($input[$attribute])) {
$query->where($attribute, $input[$attribute]);
$attributes[$attribute] = $input[$attribute];
} else {
$attributes[$attribute] = null;
}
}
return [$query->get(), $attributes];
}
示例4: image_bg_upload
public function image_bg_upload(Request $request)
{
$post = Post::query()->findOrFail($request->input('post_id'));
$img = $post->id . "-bg." . $request->file('image-bg')->getClientOriginalExtension();
$post->image = "upload/{$img}";
$post->save();
$request->file('image-bg')->move(public_path('img') . '/upload', $img);
return "{ }";
}