本文整理汇总了PHP中Post::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::create方法的具体用法?PHP Post::create怎么用?PHP Post::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
function add()
{
if (!empty($this->data)) {
$this->Post->create();
if ($this->Post->save($this->data)) {
$this->flash(__('Post saved.', true), array('action' => 'index'));
} else {
}
}
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$input = Input::only('title', 'body');
$validation = Validator::make($input, Post::$rules);
if ($validation->passes()) {
$this->post->create($input);
return Redirect::route('posts.index');
}
return Redirect::route('posts.create')->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
}
示例3: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$input = Input::all();
$validation = Validator::make($input, Post::$rules);
if ($validation->passes()) {
$this->post->create($input);
return Response::json(array('success' => true, 'errors' => '', 'message' => 'Post created successfully.'));
}
return Response::json(array('success' => false, 'errors' => $validation, 'message' => 'All fields are required.'));
}
示例4: run
public function run()
{
DB::table('categories')->delete();
Post::create(['category_name' => 'title']);
Post::create(['category_name' => 'slug']);
Post::create(['category_name' => 'excerpt']);
}
示例5: post_create
public function post_create()
{
$posts = Input::all();
$title = $posts['thread_name'];
$contentRaw = $posts['inputarea'];
if ($title != '' && strlen($contentRaw) > 10) {
$alias = Str::slug($title, '-');
$exist = Thread::where('alias', '=', $alias)->first();
if ($exist != null) {
return Redirect::to($exist->id);
}
$threadData = array('title' => $posts['thread_name'], 'alias' => $alias, 'type' => 0, 'poster_ip' => Request::ip(), 'dateline' => date("Y-m-d H:i:s"), 'last_message_at' => date("Y-m-d H:i:s"));
$thread = Thread::create($threadData);
if ($thread != null) {
$content = static::replace_at(BBCode2Html(strip_tags_attributes($contentRaw)), $thread->id);
$postData = array('thread_id' => $thread->id, 'entry' => $content, 'userip' => Request::ip(), 'user_id' => Sentry::user()->id, 'datetime' => date("Y-m-d H:i:s"), 'count' => 1, 'type' => 0);
$pst = Post::create($postData);
if ($pst != null) {
return Redirect::to($thread->id);
}
}
} else {
return Redirect::to(URL::full());
}
}
示例6: testDelete
public function testDelete()
{
$this->setExpectedException('AuthorizationRequired\\DeletePermissionException');
$normal = Post::create(self::postData());
$protected = ReadOnlyPost::find($normal->id);
$protected->delete();
}
示例7: run
public function run()
{
$faker = Faker::create();
foreach (range(1, 10) as $index) {
Post::create([]);
}
}
示例8: module_setup
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
*/
protected function module_setup()
{
$user = User::get_by_name( 'posts_test' );
if ( !$user ) {
$user = User::create( array (
'username'=>'posts_test',
'email'=>'posts_test@example.com',
'password'=>md5('q' . rand( 0,65535 ) ),
) );
}
$this->user = $user;
$post = Post::create( array(
'title' => 'Test Post',
'content' => 'These tests expect there to be at least one post.',
'user_id' => $user->id,
'status' => Post::status( 'published' ),
'content_type' => Post::type( 'entry' ),
) );
$this->post_id = $post->id;
$this->paramarray = array(
'id' => 'foofoo',
'post_id' => $this->post_id,
'name' => 'test',
'email' => 'test@example.org',
'url' => 'http://example.org',
'ip' => ip2long('127.0.0.1'),
'content' => 'test content',
'status' => Comment::STATUS_UNAPPROVED,
'date' => HabariDateTime::date_create(),
'type' => Comment::COMMENT
);
$this->comment = Comment::create( $this->paramarray );
}
示例9: run
public function run()
{
$faker = Faker\Factory::create();
for ($i = 0; $i < 25; $i++) {
$user = Post::create(array('title' => $faker->sentence($nbwords = 5), 'slug' => $faker->slug, 'content' => $faker->text, 'excerpt' => $faker->sentence, 'image' => $faker->imageUrl($width = 640, $height = 480), 'post_category_id' => '1'));
}
}
示例10: run
public function run()
{
$faker = Faker::create();
foreach (range(1, 10) as $index) {
Post::create(['title' => $faker->sentence(), 'body' => $faker->realText(500), 'user_id' => rand(1, 2)]);
}
}
示例11: run
public function run()
{
DB::table('posts')->delete();
Post::create(array('title' => 'Mi primera noticia!', 'content' => 'Hola mundo desde el contenido de la noticia'));
Post::create(array('title' => 'Mi segunda noticia!', 'content' => 'Contenido de la noticia'));
Post::create(array('title' => 'ya esto paso a la tercera noticia!', 'content' => 'Contenido de la noticia 3'));
}
示例12: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$post = ['title' => $request->input('title'), 'author' => Auth::getName(), 'content_raw' => $request->input('editorValue'), 'content_html' => $request->input('editorValue'), 'published_at' => carbon::now()];
Post::create($post);
return redirect('/admin/post');
//
}
示例13: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
// get POST data
$input = Input::all();
// set validation rules
$rules = array('title' => 'required', 'text' => 'required', 'image' => 'required');
// validate input
$validation = Validator::make($input, $rules);
// if validation fails, return the user to the form w/ validation errors
if ($validation->fails()) {
return Redirect::back()->withErrors($validation)->withInput();
} else {
// create new Post instance
$post = Post::create(array('title' => $input['title']));
// create Text instance w/ text body
$text = Text::create(array('text' => $input['text']));
// save new Text and associate w/ new post
$post->text()->save($text);
// create the new Image
$image = Image::create(array('url' => $input['image']));
// save new Text and associate w/ new post
$post->image()->save($image);
if (isset($input['tags'])) {
foreach ($input['tags'] as $tagId) {
$tag = Tag::find($tagId);
$post->tags()->save($tag);
}
}
// associate the post with the current user
$post->author()->associate(Auth::user())->save();
// redirect to newly created post page
return Redirect::route('post.show', array($post->id));
}
}
示例14: run
public function run()
{
// Uncomment the below to wipe the table clean before populating
// DB::table('posts')->truncate();
Post::create(['title' => 'test title', 'content' => 'something and more something']);
// Uncomment the below to run the seeder
// DB::table('posts')->insert($posts);
}
示例15: run
public function run()
{
DB::table('posts')->truncate();
$faker = Factory::create();
for ($i = 0; $i < 10; $i++) {
Post::create(['title' => $faker->sentence(5), 'body' => $faker->paragraph(rand(3, 5)), 'user_id' => rand(1, 3)]);
}
}