本文整理汇总了PHP中Post::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::save方法的具体用法?PHP Post::save怎么用?PHP Post::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postCreate
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function postCreate()
{
$destinationPath = '';
$filename = '';
$rules = array('title' => 'required|min:3', 'content' => 'required|min:3');
$validator = Validator::make(Input::all(), $rules);
if ($validator->passes()) {
$user = Auth::user();
$this->post->title = Input::get('title');
$this->post->slug = Str::slug(Input::get('title'));
if (Input::hasFile('img_path')) {
$file = Input::file('img_path');
$destinationPath = 'public/uploads/';
$filename = str_random(6) . '_' . $file->getClientOriginalName();
$uploadSuccess = $file->move($destinationPath, $filename);
Image::make(sprintf($destinationPath . '%s', $filename))->resize(260, 180)->save();
}
$this->post->content = Input::get('content');
$this->post->meta_title = Input::get('meta-title');
$this->post->meta_description = Input::get('meta-description');
$this->post->meta_keywords = Input::get('meta-keywords');
$this->post->user_id = $user->id;
$this->post->img_path = $destinationPath . $filename;
if ($this->post->save()) {
return Redirect::to('admin/blogs/' . $this->post->id . '/edit')->with('success', Lang::get('admin/blogs/messages.create.success'));
}
return Redirect::to('admin/blogs/create')->with('error', Lang::get('admin/blogs/messages.create.error'));
}
return Redirect::to('admin/blogs/create')->withInput()->withErrors($validator);
}
示例2: postCreate
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function postCreate()
{
$rules = array('name' => 'required|min:3');
$validator = Validator::make(Input::all(), $rules);
// Check if the form validates with success
if ($validator->passes()) {
$this->escalations->name = Input::get('name');
$this->escalations->delay = (int) Input::get('delay');
$this->escalations->reply = Input::get('reply');
$this->escalations->notify_admins = (int) Input::get('notify_admins');
$this->escalations->flag = (int) Input::get('flag');
$this->escalations->priority = json_encode(Input::get('priorities'));
$this->escalations->new_status = (int) Input::get('new_status');
$this->escalations->new_priority = (int) Input::get('new_priority');
$this->escalations->new_department = (int) Input::get('new_department');
$this->escalations->saveDeps(Input::get('departments'));
$this->escalations->saveStatuses(Input::get('statuses'));
$this->escalations->saveFlags(explode(',', Input::get('flags')));
if ($this->escalations->save()) {
return Api::to(array('success', Lang::get('l4cp-support::messages.create.success'))) ?: Redirect::to('admin/support/escalations/' . $this->escalations->id . '/edit')->with('success', Lang::get('l4cp-support::messages.create.success'));
} else {
return Api::to(array('error', Lang::get('l4cp-support::messages.create.error'))) ?: Redirect::to('admin/support/escalations/create')->with('error', Lang::get('l4cp-support::messages.create.error'));
}
} else {
return Api::to(array('error', Lang::get('l4cp-support::messages.create.error'))) ?: Redirect::to('admin/support/escalations/create')->withInput()->withErrors($validator);
}
}
示例3: postCreate
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function postCreate()
{
$rules = array('name' => 'required|min:3', 'flags' => 'required');
$validator = Validator::make(Input::all(), $rules);
// Check if the form validates with success
if ($validator->passes()) {
$this->department->name = Input::get('name');
$this->department->description = Input::get('description');
$this->department->email = Input::get('email');
$this->department->pop_host = Input::get('pop_host');
$this->department->pop_port = Input::get('pop_port');
$this->department->pop_user = Input::get('pop_user');
$this->department->pop_pass = Input::get('pop_pass');
$this->department->clients_only = (int) Input::get('clients_only');
$this->department->auto_respond = (int) Input::get('auto_respond');
$this->department->hidden = (int) Input::get('hidden');
$this->department->sort = (int) Input::get('sort');
$this->department->saveFlags(Input::get('flags'));
if ($this->department->save()) {
return Api::to(array('success', Lang::get('l4cp-support::messages.create.success'))) ?: Redirect::to('admin/support/departments/' . $this->department->id . '/edit')->with('success', Lang::get('l4cp-support::messages.create.success'));
} else {
return Api::to(array('error', Lang::get('l4cp-support::messages.create.error'))) ?: Redirect::to('admin/support/departments/create')->with('error', Lang::get('l4cp-support::messages.create.error'));
}
} else {
return Api::to(array('error', Lang::get('l4cp-support::messages.create.error'))) ?: Redirect::to('admin/support/departments/create')->withInput()->withErrors($validator);
}
}
示例4: postCreate
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function postCreate()
{
// Declare the rules for the form validation
$rules = array('title' => 'required|min:3', 'content' => 'required|min:3');
// Validate the inputs
$validator = Validator::make(Input::all(), $rules);
// Check if the form validates with success
if ($validator->passes()) {
// Create a new blog post
$user = Auth::user();
// Update the blog post data
$this->post->title = Input::get('title');
$this->post->slug = Str::slug(Input::get('title'));
$this->post->content = Input::get('content');
$this->post->meta_title = Input::get('meta-title');
$this->post->meta_description = Input::get('meta-description');
$this->post->meta_keywords = Input::get('meta-keywords');
$this->post->user_id = $user->id;
// Was the blog post created?
if ($this->post->save()) {
// Redirect to the new blog post page
return Redirect::to('admin/blogs/' . $this->post->id . '/edit')->with('success', Lang::get('admin/blogs/messages.create.success'));
}
// Redirect to the blog post create page
return Redirect::to('admin/blogs/create')->with('error', Lang::get('admin/blogs/messages.create.error'));
}
// Form validation failed
return Redirect::to('admin/blogs/create')->withInput()->withErrors($validator);
}
示例5: testBehavior
/**
* Tests correct date/time setting.
*
* @return void
* @since 0.1.0
*/
public function testBehavior()
{
// mocking failed :(
/*$post = Stub::Make(
'Post',
array(
'insert' => function () {
return true;
},
'update' => function () {
return true;
},
'name' => 'Dummy name',
'content' => 'Dummiest content',
'user_id' => 1,
'category_id' => 1,
)
);*/
$post = new \Post();
$post->setAttributes(array('name' => 'Dummy name', 'content' => 'Dummiest content', 'user_id' => 1, 'category_id' => 1), false);
$this->assertNull($post->created);
$post->save();
$dt = new \DateTime();
$this->assertSame($dt->format(\DateTime::ISO8601), $post->created);
usleep(1.1 * 1000 * 1000);
$post->save();
$this->assertSame($dt->format(\DateTime::ISO8601), $post->created);
}
示例6: testLockedFields
public function testLockedFields()
{
$post = new Post();
$post->activateLocker();
$post->activateLockCheck();
$post->setTitle('A super book');
$post->save();
$this->assertTrue($post->getTitleLock());
$this->assertEquals('A super book', $post->getTitle());
$post->setTitle('New Title');
$this->assertEquals('New Title', $post->getTitle());
$post->save();
$this->assertEquals('A super book', $post->getTitle());
}
示例7: store
public function store()
{
$files = Input::file('path');
$filesStatus = Input::get('file_status');
$status = 'success';
if ($files == null) {
Session::flash('status', 'false');
$errors_message[] = "Over max upload size!";
Session::flash('errors_message', $errors_message);
return Redirect::to('user/upload')->header('Cache-Control', 'no-store, no-cache');
}
foreach ($files as $index => $file) {
if ($file->isValid() && $filesStatus[$index] != 0) {
$post = new Post();
$post->save();
$album = $this->saveAlbum($index, $post);
if ($album) {
if (!$this->saveImage($index, $album->id, $post)) {
$status = 'false';
break;
}
} else {
$status = 'false';
break;
}
}
}
Session::flash('status', $status);
return Redirect::to('album/create')->header('Cache-Control', 'no-store, no-cache');
}
示例8: run
public function run()
{
$user = User::firstOrFail();
$post1 = new Post();
$post1->title = 'First post';
$post1->subtitle = 'This is a subtitle';
$post1->content = 'It is super easy to create a new post.';
$post1->image = 'This is an image';
$post1->user_id = $user->id;
$post1->save();
$post2 = new Post();
$post2->title = 'Second post';
$post2->subtitle = 'This is a subtitle';
$post2->content = 'It is super easy to create a new post.';
$post2->image = 'This is an image';
$post2->user_id = $user->id;
$post2->save();
$post3 = new Post();
$post3->title = 'Third post';
$post3->subtitle = 'This is a subtitle';
$post3->content = 'It is super easy to create a new post.';
$post3->image = 'This is an image';
$post3->user_id = $user->id;
$post3->save();
$post4 = new Post();
$post4->title = 'Fourth post';
$post4->subtitle = 'This is a subtitle';
$post4->content = 'It is super easy to create a new post.';
$post4->image = 'This is an image';
$post4->user_id = $user->id;
$post4->save();
}
示例9: run
public function run()
{
$user = User::firstOrFail();
$post1 = new Post();
$post1->title = '1st Blog Post';
$post1->username = 'admin';
$post1->date = '2016-01-11';
$post1->description = 'This is my first blog post on my laravel blog';
$post1->user_id = $user->id;
$post1->save();
$post2 = new Post();
$post2->title = '2nd Blog Post';
$post2->username = 'admin';
$post2->date = '2016-01-11';
$post2->description = 'This is my second blog post.';
$post2->user_id = $user->id;
$post2->save();
$post3 = new Post();
$post3->title = '3rd Blog Post';
$post3->username = 'admin';
$post3->date = '2016-01-11';
$post3->description = 'This is my third blog post';
$post3->user_id = $user->id;
$post3->save();
}
示例10: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$validator = Validator::make(Input::all(), Post::$rules);
if ($validator->fails()) {
Session::flash('errorMessage', 'Something went wrong here!');
return Redirect::back()->withErrors($validator)->withInput();
} else {
$post = new Post();
$post->title = Input::get('title');
$post->body = Input::get('body');
$post->user_id = Auth::id();
if (Input::hasFile('picture')) {
if (Input::file('picture')->isValid()) {
Storage::upload(Input::file('picture'), "{$post->picture}" . "jpg");
}
$post->picture = Input::file('picture');
}
if (Input::has('tags')) {
$post->tags = implode(', ', Input::get('tags'));
}
$post->save();
$posts = Post::paginate(5);
Session::flash('goodMessage', 'All went right here!');
return View::make('posts/index')->with('posts', $posts);
}
}
示例11: testCounterIncrementsAndDecrementsWhen
public function testCounterIncrementsAndDecrementsWhen()
{
$post_with_comments = new Post();
$post_with_comments->title = 'post 1';
$this->assertTrue($post_with_comments->save());
$post_without_comments = new Post();
$post_without_comments->title = 'post 2';
$this->assertTrue($post_without_comments->save());
//Create 10 comments, ensure counter increments
for ($i = 1; $i <= 10; $i++) {
$comment = new Comment();
$comment->postId = $post_with_comments->id;
$comment->text = 'comment ' . $i;
$this->assertTrue($comment->save());
$post_with_comments->refresh();
$post_without_comments->refresh();
$this->assertEquals($post_with_comments->commentsCount, $i);
$this->assertEquals($post_without_comments->commentsCount, 0);
}
//Delete all comments, ensure counter decrements
$comments = Comment::find()->all();
$count = count($comments);
foreach ($comments as $comment) {
$this->assertEquals($comment->delete(), 1);
$count--;
$post_with_comments->refresh();
$this->assertEquals($post_with_comments->commentsCount, $count);
}
}
示例12: run
public function run()
{
$faker = Faker::create();
for ($i = 0; $i < 30; $i++) {
$tags = ['funny', 'troll', 'sad', 'current', 'serious', 'music', 'gaming', 'technology', 'business'];
$j = 0;
$tempArray = [];
$randomNum = mt_rand(1, 3);
$post = new Post();
$post->title = $faker->catchPhrase . " " . $faker->catchPhrase;
$post->body = $faker->realText(200, 2);
$post->picture = $faker->image($dir = '/tmp', $width = 640, $height = 480);
$post->user_id = User::all()->random(1)->id;
do {
$tag = $tags[mt_rand(0, sizeof($tags) - 1)];
if ($j <= 1) {
array_push($tempArray, $tag);
unset($tags[$tag]);
} else {
$tempArray = ["{$tag}"];
unset($tags[$tag]);
}
//var j to determine how many elements have been pushed
$j++;
$randomNum--;
} while ($randomNum == 0);
$post->tags = implode(", ", $tempArray);
$post->save();
}
}
示例13: actionCreateImage
public function actionCreateImage($feed)
{
$feed = $this->loadFeed($feed);
$post = new Post(Post::IMAGE);
$post->type = Post::IMAGE;
$post->user_id = Yii::app()->user->id;
$post->feed_id = $feed->id;
if ($feed->project) {
$post->status = $feed->project->status;
}
$image = new Image();
if (!isset($_POST['Post']) || !isset($_POST['Image'])) {
$this->render('create-image', array('post' => $post, 'image' => $image));
Yii::app()->end();
}
$post->attributes = $_POST['Post'];
$image->attributes = $_POST['Image'];
$image->file = CUploadedFile::getInstance($image, 'file');
if (!$image->save()) {
$this->render('create-image', array('post' => $post, 'image' => $image));
Yii::app()->end();
}
$post->attributes = $_POST['Post'];
$post->image_id = $image->id;
if (!$post->save()) {
$image->delete();
$this->render('create-image', array('post' => $post, 'image' => $image));
Yii::app()->end();
}
$this->renderText('window.parent.location = "' . $this->createUrl('view', array('id' => $post->id)) . '";');
}
示例14: run
public function run()
{
$user = User::firstOrFail();
$post1 = new Post();
$post1->title = 'Zee\'s first blog';
$post1->body = 'This is a blog post about my time creating my personal website. It has been interesting.';
$post1->user_id = $user->id;
$post1->save();
$post2 = new Post();
$post2->title = 'What new language should I learn? ';
$post2->body = 'there has been plenty of talk about Python and Ruby. I don\'t know which way to go. But, I think Javascript is where I am going to focus mos tof my practice.... for now.';
$post2->user_id = $user->id;
$post2->save();
$post3 = new Post();
$post3->title = 'Codeup is where this was created.';
$post3->body = 'Codeup is where I spent the last 6 months developing my skills as a software engineer. Locate din the heart of San Antonio, it has helped a few hundred folks get into the coding world.';
$post3->user_id = $user->id;
$post3->save();
$post4 = new Post();
$post4->title = 'Practice, Practice, Practice';
$post4->body = 'Practice makes perfect, right? Well I need to keep developing my skills. Upddating and changing my website as needed.';
$post4->user_id = $user->id;
$post4->save();
$post5 = new Post();
$post5->title = 'This is a blog post about my life.';
$post5->body = 'Born and raised in DFW, I moved to Austin at 18 years old. I have loved it ever since. It is the only city I have ever called home.';
$post5->user_id = $user->id;
$post5->save();
}
示例15: run
public function run()
{
$user = User::firstOrFail();
$post1 = new Post();
$post1->title = "Title 1";
$post1->content = "Content 1";
$post1->user_id = $user->id;
$post1->save();
$post2 = new Post();
$post2->title = "Title 2";
$post2->content = "Content 2";
$post2->user_id = $user->id;
$post2->save();
$post3 = new Post();
$post3->title = "Title 3";
$post3->content = "Content 3";
$post3->user_id = $user->id;
$post3->save();
$post4 = new Post();
$post4->title = "Title 4";
$post4->content = "Content 4";
$post4->user_id = $user->id;
$post4->save();
$post5 = new Post();
$post5->title = "Title 5";
$post5->content = "Content 5";
$post5->user_id = $user->id;
$post5->save();
}