本文整理匯總了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 "{ }";
}