本文整理汇总了PHP中Post::first方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::first方法的具体用法?PHP Post::first怎么用?PHP Post::first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post::first方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFirst
public function testFirst()
{
$post = Post::first();
$debug = last(DB::getQueryLog());
$this->assertEquals('Bar', $post->title);
$this->assertEquals('select * from "posts" where "published" = ? and "status" = ? limit 1', $debug['query']);
}
示例2: run
public function run()
{
DB::table('comments')->delete();
$user_id = User::first()->id;
$post_id = Post::first()->id;
DB::table('comments')->insert(array(array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content2, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content3, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content2, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id + 2, 'content' => $this->content1, 'created_at' => new DateTime(), 'updated_at' => new DateTime())));
}
示例3: run
public function run()
{
DB::table('comments')->delete();
$user_id = User::first()->id;
$post_id = Post::first()->id;
DB::table('comments')->insert(array(array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content1), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content2), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content3), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content1), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content2), array('user_id' => $user_id, 'post_id' => $post_id + 2, 'content' => $this->content1)));
}
示例4: indexAction
public function indexAction($sub)
{
App::setLocale("en");
if (Input::get("lang") === "nl") {
App::setLocale("nl");
}
return View::make("index/index", ["post" => Post::first()]);
}
示例5: testSyncInManyToManyRelationship
public function testSyncInManyToManyRelationship()
{
$post = Post::forceCreate(['title' => 'Post title']);
$tag = Tag::forceCreate(['title' => 'Tag title']);
$post->tags()->sync([$tag->id]);
$this->assertEquals(1, Post::first()->tags->count());
$this->assertEquals('Tag title', Post::first()->tags()->first()->title);
}
示例6: myaccount
public function myaccount($s = "user")
{
$view = $this->getActionView();
if (RequestMethods::post('delete')) {
$del = Post::first(array('id = ?' => RequestMethods::post('id')));
$del->delete();
}
if (RequestMethods::post('block')) {
$block = User::first(array("id = ?" => RequestMethods::post('id')));
$block->live = 0;
$block->save();
}
if (RequestMethods::post('unblock')) {
$block = User::first(array("id = ?" => RequestMethods::post('id')));
$block->live = 1;
$block->save();
}
if (isset($this->_user)) {
$admin = User::first(array("admin = ?" => '1', "id = ?" => $this->user->id));
if (!empty($admin)) {
if ($s != 'post') {
$admin_table = $s::all();
}
if ($s == 'post') {
$database = Registry::get("database");
$conn = $database->initialize();
$admin_table = $conn->query()->from('posts')->join("users", "posts.from_user = users.id")->all();
}
$view->set("admin_table", $admin_table);
} else {
$posts = Post::all(array("from_user = ?" => $this->user->id));
$view->set("posts", $posts);
}
$view->set("admin", $admin)->set('table', $s);
}
}
示例7: testNonStaticCallOfFindBySlug
/**
* Test Non static call for findBySlug is working
*
* @test
*/
public function testNonStaticCallOfFindBySlug()
{
$post1 = $this->makePost('My first post');
$post1->save();
$post = Post::first();
$resultId = $post->findBySlug('my-first-post')->id;
$this->assertEquals($post1->id, $resultId);
}
示例8: testDeleteWithoutTranslations
public function testDeleteWithoutTranslations()
{
Post::forceCreate(['title' => 'Title']);
Post::i18nQuery()->truncate();
$post = Post::first();
$post->delete();
$this->assertCount(0, Post::all());
}
示例9: it_fetches_the_cover_associated_with_the_post
/** @test **/
public function it_fetches_the_cover_associated_with_the_post()
{
$this->createComponent('posts');
$this->createComponent('cover_photos');
$this->insertOn('posts', ['title' => 'Random Blog Post']);
$this->insertOn('cover_photos', ['image' => '/path/to/image.jpg']);
Post::usesOne(CoverPhoto::class);
CoverPhoto::first()->registerTo(Post::first());
$cover = Post::first()->cover_photo;
$this->assertEquals('/path/to/image.jpg', $cover->image);
}
示例10: var_dump
<?php
/**
* Copyright (c) 2014 Keith Casey.
*
* This code is designed to accompany the lynda.com video course "Design Patterns in PHP"
* by Keith Casey. If you've received this code without seeing the videos, go watch the
* videos. It will make way more sense and be more useful in general.
*/
include_once __DIR__ . '/vendor/autoload.php';
include_once 'posts.php';
echo "<pre style='color:#59E817; background-color:black; word-wrap:break-word;'>";
var_dump(Post::first());
echo '</pre>';
// $post = new Post();
//
// $post->title = 'Sample Title';
// $post->body = 'This is the body';
//
// $post->save();
示例11: testBootMethodAgainAndAgain
public function testBootMethodAgainAndAgain()
{
Post::create(['comments_count' => 2]);
$this->assertEquals(1, Post::count());
$this->assertEquals(6, Post::first()->comments_count);
}