本文整理汇总了PHP中app\models\Post::all方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::all方法的具体用法?PHP Post::all怎么用?PHP Post::all使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Post
的用法示例。
在下文中一共展示了Post::all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testIndex
public function testIndex()
{
factory(\App\Models\Post::class, 5)->create();
$postsCount = \App\Models\Post::all()->count();
// index
$this->logout()->request('GET', 'api/posts')->assertStatus(200)->assertKeyExists('result.data.0.id')->assertKeyChildrenCountEquals('result.data', $postsCount);
// @TODO pagination?
}
示例2: testModelSeed
/**
* Test samples for all models have been seeded.
*/
public function testModelSeed()
{
$message = 'Haven\'t you forgotten to run artisan migrate and db::seed?';
$this->assertNotEmpty(Author::all(), $message);
$this->assertNotEmpty(Comment::all(), $message);
$this->assertNotEmpty(Post::all(), $message);
$this->assertNotEmpty(Site::all(), $message);
}
示例3: run
public function run()
{
DB::table('comments')->delete();
$posts = Post::all()->lists('id')->toArray();
for ($i = 0; $i < 50; $i++) {
Comment::create(['post_id' => $posts[array_rand($posts, 1)], 'name' => 'Annonim', 'comment' => 'My first post', 'published' => true]);
}
}
示例4: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
//
$posts = Post::all();
$response = new \stdClass();
$response->success = true;
$response->total = count($posts);
$response->data = $posts;
return response()->json($response);
}
示例5: testModelSeed
/**
* Test samples for all models have been seeded.
*/
public function testModelSeed()
{
$message = 'Haven\'t you forgotten to run artisan migrate and db::seed?';
$this->assertNotEmpty(Author::all(), $message);
$this->assertNotEmpty(Comment::all(), $message);
$this->assertNotEmpty(Post::all(), $message);
$this->assertNotEmpty(Site::all(), $message);
$isAuthenticated = Auth::attempt(['email' => UsersTableSeeder::SAMPLE_LOGIN, 'password' => UsersTableSeeder::SAMPLE_PASSWORD]);
$this->assertTrue($isAuthenticated);
}
示例6: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$modelPost = new \App\Models\Post();
$posts = \App\Models\Post::all(['id']);
foreach ($posts as $id) {
for ($i = 0; $i < 10; $i++) {
factory(\App\Models\Comment::class)->create(['post_id' => $id->id]);
}
}
}
示例7: index
/**
* Shows all posts.
*
* @return Response
*/
public function index()
{
// Get all the post models
$posts = Post::all();
// Retrieve the user, or instantiate a new instance
$user = User::firstOrCreate(['name' => 'Chris', 'email' => 'cjsimon333@gmail.com', 'password' => 'goteam123']);
// Login with that user
Auth::login($user);
// Render the 'posts' view passing in the $posts as parameter 'posts'
return View('posts')->with('posts', $posts);
}
示例8: galeria
function galeria()
{
$posts = \App\Models\Post::all();
$tags = \App\Models\Tag::all();
$tagsUsados = [];
$tagsTotal = [];
$contTags = 0;
$contTagsTotal = 0;
foreach ($posts as $p) {
foreach ($p->tags as $t) {
$tagsUsados[$contTags] = $t->clave;
$contTags++;
}
}
foreach ($tags as $tag) {
$tagsTotal[$contTagsTotal] = $tag->clave;
$contTagsTotal++;
}
$tagsUsadosNeto = array_intersect($tagsTotal, $tagsUsados);
return view('front.galeria')->with(array('posts' => $posts, 'tags' => $tags, 'tt' => $tagsUsadosNeto));
}
示例9: function
<?php
Route::get('/', function () {
// return view('allpost');
});
// ============== all posts/single posts ============== //
Route::get('posts', function () {
$posts = \App\Models\Post::all();
return view('allpost')->with("posts", $posts);
});
Route::get('posts/{id}', function ($id) {
$post = \App\Models\Post::find($id);
return view('post', compact('post'));
});
// ============== show user/create user ============== //
Route::get('users/{id}', function ($id) {
$user = \App\Models\User::find($id);
return view('user', compact('user'));
});
Route::post('users', function (\App\Http\Requests\CreateUserRequest $request) {
$user = \App\Models\User::create($request->all());
$user->password = bcrypt('$user->password');
$user->save();
return redirect('users/' . $user->id);
});
// ============== login/out/signup ============== //
Route::get('users/create', function ($id) {
return view('signup');
});
Route::get('login', function () {
return view('login');
示例10: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$posts = \App\Models\Post::all();
return view('allPosts', ['post' => $posts]);
}
示例11: _newestPublished
}
public static function _newestPublished($amount)
{
return static::_all('is_published = 1 order by created_on desc limit ' . (int) $amount);
}
public static function _query()
{
return array('tables' => array('posts', 'categories c'), 'fields' => array('c.*', 'posts.*'), 'conditions' => array('c.category_id = posts.category_id'));
}
}
/**/
Post::event(array('_insert'), function ($self, $args, $chain) {
if (isset($args->values['title']) && !isset($args->values['original_slug'])) {
$slug = Output::slugify($args->values['title']);
//var_dump($slug);
$slugs = Post::all("original_slug LIKE ?", $slug . '%');
if ($slugs) {
$nums = array();
$slugs = array_map(function ($post) use($slug, &$nums) {
$nums[] = (int) substr($post->original_slug, strlen($slug) + 1);
return $post->original_slug;
}, $slugs);
rsort($nums, SORT_NUMERIC);
//print_r($slugs);
//print_r($nums);
$slug .= '-' . ($nums[0] + 1);
//var_dump($slug);
}
//exit;
$args->values['original_slug'] = $slug;
}
示例12: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$posts = \App\Models\Post::all();
$data = compact('posts');
return view('posts.posts', $data);
}
示例13: index
public function index()
{
$postsPerPage = $this->_config('posts_on_index');
// Way 1
// Define which get method to use to fetch Posts by checking ACL
// Use that function and the Model's logic to get those posts.
$unpub = $this->user->hasAccess('blog read unpublished');
$method = $unpub ? 'newest' : 'newestPublished';
$posts = models\Post::$method($postsPerPage);
// The quick 'n dirty //
$page = Options::one($_GET, 'page', 1, false);
$start = ($page - 1) * $postsPerPage;
$conditions = $unpub ? '1' : 'is_published = 1';
$posts = models\Post::all($conditions . ' ORDER BY created_on DESC LIMIT ' . $start . ', ' . $postsPerPage . '');
// Don't do it! //
// Way 2
// Define the difference in conditions here (instead of in the Model)
$conditions = $unpub ? '' : array('is_published' => true);
$numAllPosts = models\Post::count($conditions);
// Way 3
// A third way would be a combination like this:
/*
$access = $this->user->hasAccess('blog read unpublished');
$posts = model\Post::postsByAccess($access, $this->_config('posts_on_index'));
*/
// That way you can check access in the Controller and have fetch logic in the Model
$messages = Session::messages();
$canCreatePosts = $this->user->hasAccess('blog create posts');
return get_defined_vars();
// view will be rendered by row\Controller->_post_action
return $this->_display(__METHOD__, get_defined_vars(), !$this->AJAX);
// view will be rendered by Output->display
return $this->_display(get_defined_vars());
// view will be rendered by Output->display
}
示例14: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$this->checkParametersEmpty();
return $this->getResponse(Post::all());
}
示例15: index
public function index()
{
$posts = Post::all();
return $this->response->array($posts);
}