当前位置: 首页>>代码示例>>PHP>>正文


PHP Posts::save方法代码示例

本文整理汇总了PHP中app\Posts::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Posts::save方法的具体用法?PHP Posts::save怎么用?PHP Posts::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Posts的用法示例。


在下文中一共展示了Posts::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(PostFormRequest $request)
 {
     $title = $request->get('title');
     $duplicate = \DB::table('posts')->where('title', $title)->get();
     //		var_dump($duplicate);
     //		die();
     if ($duplicate != null) {
         return redirect('/new-post')->withErrors('A post with this title already exists');
     }
     $post = new Posts();
     $post->title = $request->get('title');
     $post->body = $request->get('body');
     $post->slug = str_slug($post->title);
     $post->author_id = $request->user()->id;
     $category_id = $request->get('category');
     //		var_dump($category_id);
     //		die();
     $post->category_id = $category_id;
     if ($request->has('save')) {
         $post->active = 0;
         $message = 'Post saved successfully';
     } else {
         $post->active = 1;
         $message = 'Post published successfully';
     }
     $post->save();
     return redirect('edit/' . $post->slug)->withMessage($message);
 }
开发者ID:calimanleontin,项目名称:bet,代码行数:33,代码来源:PostController.php

示例2: addPost

 public function addPost(Request $request)
 {
     $newPost = new Posts();
     $newPost->title = $request->title;
     $newPost->body = $request->body;
     $newPost->save();
     return $newPost;
 }
开发者ID:shadowfox476,项目名称:hannahs_blog,代码行数:8,代码来源:PostsController.php

示例3: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $xml = simplexml_load_file('http://www.buzzfeed.com/index.xml', 'SimpleXMLElement', LIBXML_NOCDATA);
     $count = 0;
     foreach ($xml->channel->item as $article) {
         $title = $article->title;
         $url = $article->link;
         $author = $article->author;
         $start = strpos($article->pubDate, ',');
         $date = substr($article->pubDate, $start + 2, -15);
         $date = explode(' ', $date);
         $day = $date[0];
         //day
         $month = $date[1];
         //month
         $month = substr(Carbon::parse($month), 5, 2);
         $year = $date[2];
         //year
         $date = substr(Carbon::createFromFormat("Y-m-d", $year . "-" . $month . "-" . $day), 0, 10);
         $description = $article->description;
         $imgPos = strpos($description, '<img');
         $imgUrl = null;
         if ($imgPos != null) {
             $imgString = substr($description, $imgPos);
             $srcPos = strpos($imgString, 'src=');
             $src = substr($imgString, $srcPos + 5);
             $tok = '"';
             $endQuotePos = strpos($src, $tok);
             $imgUrl = substr($src, 0, $endQuotePos);
         }
         $id = DB::table('email_articles')->where('post_date', $date)->value('article_id');
         if ($count < 5) {
             if (!isset($imgUrl)) {
             } else {
                 if (Posts::where('title', '=', $title)->exists()) {
                     echo $title . " already exists";
                 } else {
                     $post = new Posts();
                     $post->article_id = $id;
                     $post->author = $author;
                     $post->title = $title;
                     $post->description = 'N/A';
                     $post->imgUrl = $imgUrl;
                     $post->url = $url;
                     $post->source = 'BuzzFeed';
                     $post->save();
                     echo "stored " . $title . "!";
                 }
                 $count++;
             }
         }
     }
 }
开发者ID:kcunanan,项目名称:claremontrise,代码行数:58,代码来源:GetBuzzFeed.php

示例4: store

 public function store(Request $request)
 {
     $post = new Posts();
     $post->title = $request->get('title');
     $post->body = $request->get('body');
     $post->slug = substr(md5(rand()), 0, 7) . '-';
     $post->slug = $post->slug . str_slug($post->title);
     $post->author_id = $request->user()->id;
     $post->active = 1;
     $post->save();
     return redirect('/' . $post->slug);
 }
开发者ID:anmolarora,项目名称:MyBlog_PHP,代码行数:12,代码来源:PostController.php

示例5: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $post = new Posts();
     // model
     $post->message = $request->get('message');
     $post->user_id = $request->user()->id;
     $post->address = "dwd";
     $post->longitude = 12;
     $post->latitude = 12;
     $post->post_picture = "2323";
     $post->type = "found";
     $post->save();
     // return redirect('home');
 }
开发者ID:DenicijaStojanovska,项目名称:pet-care,代码行数:20,代码来源:PostController.php

示例6: savePost

 public function savePost(Request $request)
 {
     $input = Input::except('_token', 'image', 'x', 'y', 'w', 'h', 'old_image');
     $update = new Posts();
     foreach ($input as $key => $value) {
         if (!empty($key) && $key == 'expdate') {
             $update->{$key} = strtotime($value);
         } else {
             $update->{$key} = $value;
         }
     }
     $update->user_id = Auth::user()->id;
     $update->save();
     $inserted_id = $update->id;
     $image = Input::file('image');
     if (!empty($image)) {
         $filename = time() . '.' . $image->getClientOriginalExtension();
         $path = public_path('post_images/' . $filename);
         $image_x = $request->x;
         $image_y = $request->y;
         $image_width = $request->w;
         $image_height = $request->h;
         $old_image = $request->old_image;
         Image::make($image->getRealPath())->crop($image_width, $image_height, $image_x, $image_y)->resize(640, 360)->save($path);
         File::delete($old_image);
         $imgUpdate = Posts::find($inserted_id);
         $imgUpdate->image = $filename;
         $imgUpdate->save();
     }
     $audio = Input::file('audio');
     if (!empty($audio)) {
         $filename = time() . '.' . $audio->getClientOriginalExtension();
         $path = public_path('post_audios/');
         $request->file('audio')->move($path, $filename);
         $update = Posts::find($inserted_id);
         $update->audio = $filename;
         $update->save();
     }
     $video = Input::file('video');
     if (!empty($video)) {
         $filename = time() . '.' . $video->getClientOriginalExtension();
         $path = public_path('post_videos/');
         $request->file('video')->move($path, $filename);
         $update = Posts::find($inserted_id);
         $update->video = $filename;
         $update->save();
     }
     return Redirect::back()->with('message', 'Posted Successfully');
 }
开发者ID:keshavkatwe,项目名称:advsystem,代码行数:49,代码来源:Post.php

示例7: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $post = new Posts();
     $post->idpengguna = Auth::user()->id;
     $post->judul = Input::get('judul');
     $post->isi = Input::get('isi');
     $post->tag = Input::get('tag');
     $post->slug = str_slug(Input::get('judul'));
     if (Input::hasFile('sampul')) {
         $sampul = date("YmdHis") . uniqid() . "." . Input::file('sampul')->getClientOriginalExtension();
         Input::file('sampul')->move(storage_path(), $sampul);
         $post->sampul = $sampul;
     }
     $post->save();
     return redirect(url('artikel'));
 }
开发者ID:ariefsetya,项目名称:blog,代码行数:21,代码来源:ArtikelController.php

示例8: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(PostFormRequest $request)
 {
     $post = new Posts();
     $post->title = $request->get('title');
     $post->body = $request->get('body');
     $post->slug = str_slug($post->title);
     $post->author_id = $request->user()->id;
     if ($request->has('save')) {
         $post->active = 0;
         $message = 'Post saved successfully';
     } else {
         $post->active = 1;
         $message = 'Post published successfully';
     }
     $post->save();
     return redirect('edit/' . $post->slug)->withMessage($message);
 }
开发者ID:GanjaGanja,项目名称:blog,代码行数:23,代码来源:PostController.php

示例9: postNewsFeed

 public function postNewsFeed(Request $request)
 {
     $this->validate($request, ['status' => 'required|max:255']);
     $post = new Posts();
     $post->status = $request->get('status');
     if ($request->file('photo') == '') {
         $post->photo = 'noImage.jpg';
     } else {
         $fileName = uniqid() . '.' . $request->file('photo')->getClientOriginalExtension();
         // \Image::make($request->file('photo') )
         //     ->resize(750, null, function($constraint){
         //         $constraint->aspectRatio();
         //     })->save('img/Post/'.$fileName);
         \Image::make($request->file('photo'))->save('img/Post/' . $fileName);
         $post->photo = $fileName;
     }
     $post->user_id = \Auth::user()->id;
     $post->save();
     return redirect('home');
 }
开发者ID:np-patel,项目名称:exploreTasman,代码行数:20,代码来源:HomeController.php

示例10: savePost

 public function savePost(Request $request)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $data = $request->all();
     $post = new Posts();
     $post->CourseID = $data['CourseID'];
     $post->FormatID = $data['FormatID'];
     $post->ThumbnailID = $data['ThumbnailID'];
     $post->Title = $data['Title'];
     $post->Description = $data['Description'];
     $post->FreeQuestions = $data['FreeQuestions'];
     switch ($data['ThumbnailID']) {
         case '1':
             // Plain Text
             $post->save();
             $post = Posts::orderBy('id', 'desc')->first();
             //Photo
             $file = $request->file('Photo');
             //              $file = Request::file('Photo');
             $post->Photo = 'Post_' . $data['CourseID'] . '_' . $post->id . "_-Evangels-English-www.evangelsenglish.com_" . "." . $file->getClientOriginalExtension();
             $file->move(base_path() . '/public/images/imagePost/', $post->Photo);
             // (intval(Posts::orderBy('created_at', 'desc')->first()->id) + 1)
             $post->update();
             break;
         case '2':
             // Video
             $linkVideo = $data['Video'];
             $post->Video = PostsController::getYoutubeVideoID($linkVideo);
             $post->save();
             break;
     }
     $course = Courses::find($post->CourseID);
     $course->NoOfPosts++;
     $course->update();
     // Save Hashtag
     $rawHT = $data['Hashtag'];
     TagsController::tag($rawHT, $post->id);
     return redirect(route('admin.viewcourse', $post->CourseID));
 }
开发者ID:kevinhoa95,项目名称:e-learning,代码行数:41,代码来源:PostsController.php

示例11: store

 public function store(Request $request)
 {
     if ($request->ajax()) {
         $new_header = $request->input('Header');
         $new_content = $request->input('Content');
         $v = Validator::make($request->all(), ['Header' => 'required|max:32', 'Content' => 'required']);
         if (!$v->fails()) {
             $post = new Posts();
             $post->Header = $new_header;
             $post->Content = $new_content;
             if ($post->save()) {
                 $response = array('status' => 'success', 'msg' => 'Setting created successfully');
             } else {
                 $response = array('status' => 'error', 'msg' => 'save failed');
             }
         } else {
             $response = array('status' => 'error', 'msg' => 'v failed');
         }
         return Response::json($response);
     }
 }
开发者ID:austin43,项目名称:personal-site,代码行数:21,代码来源:NewPost.php

示例12: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //
     if ($this->checkauth(1)['err'] == 1) {
         return $this->checkauth(1)['view'];
     }
     $post = new Posts();
     $post->judul = Input::get('judul');
     $post->slug = str_slug(Input::get('judul'));
     if (Input::hasFile('sampul') and Input::file('sampul')->isValid()) {
         $sampul = date("YmdHis") . uniqid() . "." . Input::file('sampul')->getClientOriginalExtension();
         Input::file('sampul')->move(storage_path() . '/sampulpost', $sampul);
         $post->sampul = $sampul;
     }
     $post->idpengguna = Auth::user()->id;
     $post->idcategory = Input::get('idcategory');
     $post->tags = Input::get('tags');
     $post->isi = Input::get('isi');
     $post->save();
     return redirect(url('mine/posts'));
 }
开发者ID:ariefsetya,项目名称:it-club,代码行数:26,代码来源:PostController.php

示例13: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $client = new Client();
     $crawler = $client->request('GET', 'http://claremontindependent.com/category/campus-news/');
     $status_code = $client->getResponse()->getStatus();
     if ($status_code == 200) {
         echo '200 OK<br>';
     }
     $crawler->filter('div.site-content article')->each(function ($node) {
         $url = $node->filter('a.post-thumbnail')->attr('href');
         //url
         $imgUrl = $node->filter('a.post-thumbnail img')->attr('src');
         //imgUrl
         $title = $node->filter('header h1')->text();
         //title
         $date = substr($node->filter('header div.entry-meta span.entry-date time')->attr('datetime'), 0, 10);
         //date
         $author = $node->filter('header div.entry-meta span.byline span.author a')->text();
         //author
         $description = substr(mb_convert_encoding($node->filter('div.entry-content p')->text(), "HTML-ENTITIES", "UTF-8"), 0, 500);
         //description
         $id = getArticleId($date);
         if (Posts::where('title', '=', $title)->exists()) {
             echo $title . " already exists";
         } else {
             $post = new Posts();
             $post->article_id = $id;
             $post->author = $author;
             $post->title = $title;
             $post->description = $description;
             $post->imgUrl = $imgUrl;
             $post->url = $url;
             $post->source = 'Claremont Independent';
             $post->save();
             echo "stored " . $title . "!";
         }
     });
     $client = new Client();
     $crawler = $client->request('GET', 'http://www.thegoldenantlers.com/');
     $status_code = $client->getResponse()->getStatus();
     if ($status_code == 200) {
         echo '200 OK<br>';
     }
     $count = 0;
     $crawler->filter('div.bl_posts_information')->each(function ($node, $count) {
         if ($count == 0) {
             $node->filter('article')->each(function ($node1) {
                 $author = ucwords(str_replace('-', ' ', $node1->attr('data-categoryslug')));
                 //author
                 $url = $node1->filter('div.post-image a')->attr('href');
                 //url
                 $imgUrl = $node1->filter('div.post-image img')->attr('src');
                 //imgUrl
                 $date = $node1->filter('div.post-image div.meta-info div.info-date time')->attr('datetime');
                 //date
                 $date = substr(createDateAntlers($date), 0, 10);
                 $title = $node1->filter('div.post-body h3')->text();
                 //title
                 $description = str_replace("CONTINUE READING", "", trimWhiteSpace(str_replace("&nbsp;", "", mb_convert_encoding($node1->filter('div.post-body div.post-content p')->text(), "HTML-ENTITIES", "UTF-8"))));
                 //description
                 $id = getArticleId($date);
                 if (Posts::where('title', '=', $title)->exists()) {
                     echo $title . " already exists";
                 } else {
                     $post = new Posts();
                     $post->article_id = $id;
                     $post->author = $author;
                     $post->title = $title;
                     $post->description = $description;
                     $post->imgUrl = $imgUrl;
                     $post->url = $url;
                     $post->source = 'The Golden Antlers';
                     $post->save();
                     echo "stored " . $title . "!";
                 }
             });
         }
         $count++;
     });
     $client = new Client();
     $crawler = $client->request('GET', 'http://cmcforum.com/');
     $status_code = $client->getResponse()->getStatus();
     if ($status_code == 200) {
         echo '200 OK<br>';
     }
     $count = 0;
     $crawler->filter('div.td-big-grid-wrapper div.td-big-grid-post')->each(function ($node, $count) {
         if ($count == 0) {
             $url = $node->filter('div.td-module-thumb a')->attr('href');
             //url no clean
             $imgUrl = $node->filter('a img')->attr('src');
             //imgUrl no clean
             $title = $node->filter('div.td-big-grid-meta h3 a')->text();
             //clean title
             $date = substr($node->filter('div.td-big-grid-meta div.td-module-meta-info div.td-post-date time')->attr('datetime'), 0, 10);
//.........这里部分代码省略.........
开发者ID:kcunanan,项目名称:claremontrise,代码行数:101,代码来源:ScrapePosts.php

示例14: scrapeForum

 public function scrapeForum()
 {
     $client = new Client();
     $crawler = $client->request('GET', 'http://cmcforum.com/');
     $status_code = $client->getResponse()->getStatus();
     if ($status_code == 200) {
         echo '200 OK<br>';
     }
     $count = 0;
     $crawler->filter('div.td-big-grid-wrapper div.td-big-grid-post')->each(function ($node, $count) {
         if ($count == 0) {
             $url = $node->filter('div.td-module-thumb a')->attr('href');
             //url no clean
             $imgUrl = $node->filter('a img')->attr('src');
             //imgUrl no clean
             $title = $node->filter('div.td-big-grid-meta h3 a')->text();
             //clean title
             $date = substr($node->filter('div.td-big-grid-meta div.td-module-meta-info div.td-post-date time')->attr('datetime'), 0, 10);
             //date clean
             $author = $node->filter('div.td-big-grid-meta div.td-module-meta-info div.td-post-author-name a')->text();
             //author clean
             $client2 = new Client();
             $crawler2 = $client2->request('GET', $url);
             $description = $crawler2->filter('div.td-post-content p')->text();
             $id = DB::table('email_articles')->where('post_date', $date)->value('article_id');
             if (Posts::where('title', '=', $title)->exists()) {
                 echo $title . " already exists";
             } else {
                 $post = new Posts();
                 $post->article_id = $id;
                 $post->author = $author;
                 $post->title = $title;
                 $post->description = $description;
                 $post->imgUrl = $imgUrl;
                 $post->url = $url;
                 $post->source = 'The Forum';
                 $post->save();
                 echo "stored " . $title . "!";
             }
         }
         $count++;
     });
 }
开发者ID:kcunanan,项目名称:claremontrise,代码行数:43,代码来源:CollegePostsController.php

示例15: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(PostFormRequest $request)
 {
     // dd($request->all());
     // anonymous detector
     if (Auth::guest()) {
         if (empty($request->get('name'))) {
             // $name = 'anonymous';
             Auth::loginUsingId(2);
         } else {
             $guest_name = $request->get('name');
             // get computer ip address if not anonymous
             // $ip = Request::getClientIp();
             $ip = $_SERVER['REMOTE_ADDR'];
         }
     }
     // validate slug availability (route name check + existing slugs)
     $ugly_slug = $request->get('title');
     $title_special_removed = preg_replace('/[^A-Za-z0-9\\-]/', '', $ugly_slug);
     $posted_slug = str_slug($title_special_removed);
     $existing_slugs = Posts::where('slug', '=', $posted_slug)->count();
     $routes = array();
     $routeCollection = Route::getRoutes();
     foreach ($routeCollection as $route) {
         $routes[] = $route->getPath();
     }
     // if found in either route check or db, fail the post
     if (in_array($posted_slug, $routes) || $existing_slugs > 0) {
         // echo "validation failed";
         if (!Auth::user()->is_admin()) {
             Auth::logout();
         }
         return redirect('new-post')->withErrors('This title is unavailble. Please choose a new one.')->withInput();
     }
     $post = new Posts();
     $post->title = $request->get('title');
     $post->body = $request->get('body');
     $post->slug = str_slug($post->title);
     if (Auth::guest()) {
         $post->author_id = 3;
         $post->guest_name = $guest_name;
         $post->ip_address = $ip;
     } else {
         $post->author_id = $request->user()->id;
     }
     if ($request->has('save')) {
         $post->active = 0;
         $message = 'Post Saved Successfully';
     } else {
         if (!Auth::guest() && $request->user()->is_admin()) {
             $post->active = 1;
             $message = 'Post Published Successfully';
         } else {
             $post->active = 0;
             $message = 'Post Pending Approval';
             Auth::logout();
         }
     }
     $post->save();
     // gather info for the mailer
     // $admin_email 	= User::find(1)->email;
     // $admin_email = User::where('role', 'admin')->get();
     $admin_email = User::where('role', 'admin')->whereNotIn('id', [1])->get();
     $title = $post->title;
     $body = $post->body;
     $slug = $post->slug;
     // email admin
     if (isset($post->guest_name)) {
         $name = $post->guest_name;
     } else {
         $name = User::find($post->author_id)->name;
     }
     $data['admin_email'] = $admin_email;
     $data['title'] = $title;
     $data['body'] = $body;
     $data['slug'] = $slug;
     $data['name'] = $name;
     Mail::send('emails.newpost', $data, function ($message) use($admin_email, $title, $body, $slug, $name) {
         $message->from(Config::get('services.email.from'), 'Whiteboard');
         foreach ($admin_email as $admin) {
             $message->to($admin->email, $admin->name);
         }
         $message->subject('Whiteboard - New Post');
     });
     // return redirect('edit/'.$post->slug)->withMessage($message);
     return redirect('/')->withMessage($message);
 }
开发者ID:ehumps,项目名称:whiteboard,代码行数:91,代码来源:PostController.php


注:本文中的app\Posts::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。