本文整理汇总了PHP中Post::all方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::all方法的具体用法?PHP Post::all怎么用?PHP Post::all使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post::all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: submit_link
public function submit_link()
{
// for submitting the link created to the database
$submit_link = Post::submit_link();
$posts = Post::all();
require_once 'views/posts/index.php';
}
示例2: adminDashboard
public function adminDashboard()
{
$moderate_count = User::where('role_id', 1)->get()->count();
$post_count = Post::all()->count();
$posts = Post::orderBy('id', 'desc')->distinct()->where('is_approved', 1)->take(5)->get();
return View::make('admin.adminDashboard')->withPage('dashboard')->with('moderate_count', $moderate_count)->with('post_count', $post_count)->withPosts($posts);
}
示例3: testAll
public function testAll()
{
$post = Post::all();
$debug = last(DB::getQueryLog());
$this->assertCount(3, $post);
$this->assertEquals('select * from "posts" where "published" = ? and "status" = ?', $debug['query']);
}
示例4: dashboard
/**
* Show Admin Dashboard
* GET /admin/dashboard
*
* @return Response
*/
public function dashboard()
{
$users = \DB::table('users')->count();
$posts = \Post::all()->count();
$feedback = \Feedback::all()->count();
return \View::make('admin.dashboard', compact('posts', 'users', 'feedback'));
}
示例5: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$posts = Post::all();
$data = compact('posts');
// equal to ->with('posts', $posts);
return View::make('home.index')->with('posts', $posts);
}
示例6: testPaginate
public function testPaginate()
{
$posts = Paginator::paginatePosts(Post::all(), 0, 5);
$res = $this->e->paginate($posts, 'year');
$keys = array_keys($res);
$this->assertTrue(2010 < $keys[0] and $keys[0] < 2020);
$this->assertTrue(isset($res[$keys[0]]['posts']));
}
示例7: run
public function run()
{
$faker = Faker::create();
Comment::truncate();
$posts = Post::all();
foreach (range(1, 50) as $index) {
Comment::create(['user_id' => $faker->numberBetween($min = 1, $max = 10), 'post_id' => rand(1, $posts->count()), 'text' => $faker->paragraph($nbSentences = 3), 'attachment_id' => 0]);
}
}
示例8: index
/**
* Display a listing of the resource.
* @param live
* @return Response
*/
public function index($live = null)
{
if (isset($live)) {
$posts = Post::where('live', $live)->get();
} else {
$posts = Post::all();
}
return $posts;
}
示例9: isUniqueSlug
public function isUniqueSlug($slug)
{
$posts = Post::all();
foreach ($posts as $post) {
if ($post->slug == $slug) {
return false;
}
}
return true;
}
示例10: addLang
public static function addLang($lang_id)
{
$pages = Post::all();
foreach ($pages as $item) {
$page_lang = new PostLang();
$page_lang->lang_id = $lang_id;
$page_lang->post_id = $item->id;
$page_lang->save();
}
}
示例11: run
public function run()
{
$faker = Faker::create();
//add these posts
for ($i = 0; $i < 10; $i++) {
$comment = new Comment();
$comment->post_id = Post::all()->random(1)->id;
$comment->user_id = User::all()->random(1)->id;
$comment->comment = $faker->text($maxNbChars = 200);
$comment->save();
}
}
示例12: index
public function index()
{
// Check if user has sent a search query
if ($query = Input::get('query', false)) {
// Use the Elasticquent search method to search ElasticSearch
// $posts = Post::search($query);
$posts = Post::searchByQuery(["bool" => ['must' => ['multi_match' => ['query' => Input::get('query', ''), 'fields' => ["title^2", "content"]]], "should" => ['match' => ['tags' => ["query" => Input::get('query', ''), "type" => "phrase"]]]]]);
} else {
// Show all posts if no query is set
$posts = Post::all();
}
return View::make('home', compact('posts'));
}
示例13: blog
public function blog()
{
$this->load->model('post');
$this->load->library('pagination');
$posts = Post::all();
$config['base_url'] = base_url() . 'blog/page/';
$config['total_rows'] = $posts->count();
$config['per_page'] = 5;
$skip = ($this->uri->segment(3) - 1) * $config['per_page'];
$this->pagination->initialize($config);
$data = ['menu' => 'blog', 'posts' => Post::orderBy('created_at', 'desc')->skip($skip)->take($config['per_page'])->get(), 'links' => $this->pagination->create_links()];
$this->load->view('front/blog', $data);
}
示例14: run
public function run()
{
/*delete all existing images*/
DB::table('images')->delete();
$faker = Faker::create();
for ($i = 0; $i < 10; $i++) {
$image = new Image();
$image->post_id = Post::all()->random()->id;
$image->url = $faker->imageUrl(640, 480, 'city');
$image->image_title = '';
$image->save();
}
}
示例15: tags
public function tags($slug)
{
if (!$slug) {
redirect('web');
}
// $join = 'LEFT JOIN post_to_tags a ON(posts.id = a.post_id) WHERE tag_id = '.$id.' AND post_status = "active"' ;
$join = " LEFT JOIN post_to_tags a " . "ON(posts.id = a.post_id) " . "WHERE a.tag_id = " . Tag::first(array('slug' => $slug))->id . " " . "AND post_type = 'post' ORDER BY id DESC";
$data['posts'] = Post::all(array('joins' => $join));
$data['navs'] = Post::all(array('post_type' => 'page'));
if (!$data['posts']) {
redirect('web/error/404/NotFound');
}
$this->theme->view('tags', $data);
}