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


PHP Post::create方法代码示例

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


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

示例1: store

 public function store()
 {
     $posts = \Input::get('posts');
     $results = array();
     if (count($posts)) {
         $insertData = [];
         foreach ($posts as $post) {
             $tags = isset($post['tags']) ? $post['tags'] : array();
             $result = Post::create(array('title' => $post['title'], 'body' => $post['body']));
             if (count($tags) && $result) {
                 $this->savePostTags($result->id, $tags);
             }
             array_push($results, $result);
         }
         if (count($results)) {
             $emails = json_decode(\Storage::get('emails.json'), true);
             \Mail::send('emails.post', ['results' => $results], function ($message) use($emails) {
                 $message->from(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'));
                 $message->to($emails)->subject('New posts');
             });
             Cache::forget('all_post');
             return self::makeResponse($results, 201);
         } else {
             return self::makeResponse(array(), 500, 'Server Error');
         }
     } else {
         return self::makeResponse(array(), 400, 'Bad Request');
     }
 }
开发者ID:vanhonit,项目名称:lazada,代码行数:29,代码来源:PostController.php

示例2: run

 public function run()
 {
     DB::table('Posts')->delete();
     Post::create(['name' => 'First Name', 'email' => 'test_mail1@test.lt', 'city' => 1, 'content' => 'First Feedbuck 24', 'slag' => 'first-feed', 'published' => true, 'created_at' => time(), 'mood' => '1']);
     Post::create(['name' => 'Second Name', 'email' => 'test_mail1@test.lt', 'city' => 2, 'content' => 'Second Feedbuck 24', 'slag' => 'second-feed', 'published' => true, 'created_at' => time(), 'mood' => '2']);
     Post::create(['name' => 'Third Name', 'email' => 'test_mail3@test.lt', 'city' => 3, 'content' => 'Third Feedbuck 24sdsds', 'slag' => 'third-feed', 'published' => true, 'created_at' => time(), 'mood' => '1']);
 }
开发者ID:ruslankus,项目名称:lavarel-lessons,代码行数:7,代码来源:DatabaseSeeder.php

示例3: run

 public function run()
 {
     DB::table('posts')->delete();
     Post::create(['title' => 'First Post', 'content' => 'My first post', 'author' => 'Yevgeniy Zholkevskiy', 'published' => true]);
     Post::create(['title' => 'Two Post', 'content' => 'My second post', 'author' => 'Yevgeniy Zholkevskiy', 'published' => true]);
     Post::create(['title' => 'Three Post', 'content' => 'My third post', 'author' => 'Yevgeniy Zholkevskiy', 'published' => true]);
 }
开发者ID:black-bullet,项目名称:laravel-blog,代码行数:7,代码来源:PostsSeeder.php

示例4: store

 public function store(Request $request)
 {
     $this->validate($request, ['title' => 'required', 'content' => 'required', 'author' => 'required']);
     $input = $request->all();
     Post::create($input);
     return redirect()->route('posts.index');
 }
开发者ID:black-bullet,项目名称:laravel-blog,代码行数:7,代码来源:PostController.php

示例5: run

 public function run()
 {
     DB::table('Posts')->delete();
     Post::create(['title' => 'First Post', 'author' => 'Евгений', 'excerpt' => 'First Post body', 'text' => 'Content First Post body', 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
     Post::create(['title' => 'Second Post', 'author' => 'Евгений', 'excerpt' => 'Second Post body', 'text' => 'Content Second Post body', 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
     Post::create(['title' => 'Third Post', 'author' => 'Евгений', 'excerpt' => 'Third Post body', 'text' => 'Content Third Post body', 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
 }
开发者ID:evnazarchuk,项目名称:laravel5-test,代码行数:7,代码来源:DatabaseSeeder.php

示例6: create

 /**
  * Show the application welcome screen to the user.
  *
  * @return Response
  */
 public function create(Request $request, $id = '')
 {
     //echo Auth::user()->id; exit;
     if (empty($id)) {
         $model = new \App\Models\Post();
     } else {
         $model = \App\Models\Post::find($id);
         if (is_null($model)) {
             return response()->view('errors.404', array(), 404);
         }
     }
     if ($request->isMethod('post')) {
         $this->validate($request, ['title' => 'required|max:255', 'content' => 'required']);
         $title = \Illuminate\Support\Facades\Request::input('title');
         $content = \Illuminate\Support\Facades\Request::input('content');
         $publish = \Illuminate\Support\Facades\Request::input('publish') === null ? 0 : 1;
         if (empty($id)) {
             \App\Models\Post::create(array('title' => $title, 'content' => $content, 'publish' => $publish, 'user_id' => (int) Auth::user()->id, 'created_at' => date('Y-m-d H:i:s')));
         } else {
             $model->fill(['title' => $title, 'content' => $content, 'publish' => $publish, 'updated_at' => date('Y-m-d H:i:s')]);
             $model->save();
         }
         //echo "23423"; exit;
         return redirect()->to('/');
     }
     return view('post.create')->with(compact('model'));
 }
开发者ID:veretilosergei1985,项目名称:laravel,代码行数:32,代码来源:PostController.php

示例7: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Post $postModel, Request $request)
 {
     //dd($request->all());
     //$request=$request->except('_token');
     $postModel->create($request->all());
     return redirect()->route('posts');
 }
开发者ID:densem-2013,项目名称:Laravel_local,代码行数:12,代码来源:PostController.php

示例8: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(PostCreateRequest $request)
 {
     //
     $post = Post::create($request->postFillData());
     $post->syncTags($request->get('tags', []));
     return redirect()->route('admin.post.index')->withSuccess('New Post Successful Created');
 }
开发者ID:saviorZSC,项目名称:zsc_laravel,代码行数:12,代码来源:PostController.php

示例9: run

 public function run()
 {
     DB::table('Posts')->delete();
     Post::create(['title' => 'First Post', 'slug' => 'first-post', 'excerpt' => 'First Post body', 'content' => 'Content First Post body', 'published' => true, 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
     Post::create(['title' => 'Second Post', 'slug' => 'second-post', 'excerpt' => 'Second Post body', 'content' => 'Content Second Post body', 'published' => false, 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
     Post::create(['title' => 'Third Post', 'slug' => 'third-post', 'excerpt' => 'Third Post body', 'content' => 'Content Third Post body', 'published' => false, 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
 }
开发者ID:billizzard,项目名称:hobby,代码行数:7,代码来源:DatabaseSeeder.php

示例10: store

 /**
  * Store a newly created post in storage.
  *
  * @param CreatepostRequest $request
  *
  * @return Response
  */
 public function store(CreatePostRequest $request)
 {
     $input = Request::all();
     if (!empty($input['imagen'])) {
         $this->carpeta = 'posts/' . $input['id_usuario'] . '/';
         if (!File::exists($this->carpeta)) {
             //Crear carpeta de archivos adjuntos
             File::makeDirectory($this->carpeta);
         }
         $filename = 'posts/' . $input['id_usuario'] . '/' . $input['titulo'] . date("GisdY") . '.jpg';
         $input['imagen'] = $filename;
         Image::make(Input::file('imagen'))->resize(480, 360)->save($filename);
     }
     if (!empty($input['archivo'])) {
         $this->carpeta = 'posts/' . $input['id_usuario'] . '/';
         if (!File::exists($this->carpeta)) {
             //Crear carpeta de archivos adjuntos
             File::makeDirectory($this->carpeta);
         }
         $destinationPath = 'posts/' . $input['id_usuario'] . '/';
         // upload path
         $nombre = Input::file('archivo')->getClientOriginalName();
         // getting image extension
         Input::file('archivo')->move($destinationPath, $nombre);
         $input['archivo'] = $destinationPath . $nombre;
     }
     $post = Post::create($input);
     return redirect('home');
 }
开发者ID:ProyectoSanClemente,项目名称:proyectoapi5.1,代码行数:36,代码来源:PostController.php

示例11: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     if (!$request->title or !$request->post or !$request->user_id) {
         return Response::json(['error' => ['message' => 'Insufficient data']], 422);
     }
     $post = Post::create($request->all());
     return Response::json(['message' => 'Post Created Succesfully', 'data' => $this->transform($post)]);
 }
开发者ID:ganeshkanawade,项目名称:laravel-setup,代码行数:14,代码来源:PostsController.php

示例12: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Post::truncate();
     foreach (range(1, 10) as $value) {
         $faker = \Faker\Factory::create('zh_TW');
         Post::create(['title' => $faker->title, 'content' => $faker->name, 'is_feature' => rand(1, 0), 'page_view' => rand(1, 1000), 'created_at' => Carbon::now()->subDays($value), 'updated_at' => Carbon::now()->subDays($value)]);
     }
 }
开发者ID:y850830,项目名称:blog,代码行数:13,代码来源:PostTableSeeder.php

示例13: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Post::truncate();
     foreach (range(10, 1) as $num) {
         $faker = Faker\Factory::create('zh_TW');
         Post::create(['title' => $faker->name, 'content' => $faker->sentence, 'id' => rand(0, 100), 'created_at' => $faker->dateTime($max = 'now'), 'updated_at' => Carbon::now()->subDays($num)->subYears(rand(1, 5))]);
     }
 }
开发者ID:MENG-WEI-LUN,项目名称:Seeding,代码行数:13,代码来源:PostTableSeeder.php

示例14: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Post::truncate();
     $faker = Factory::create('zh_tw');
     foreach (range(10, 1) as $number) {
         Post::create(['title' => $faker->title, 'is_feature' => rand(0, 1), 'content' => $faker->name, 'created_at' => Carbon::now()->subDay($number), 'updated_at' => Carbon::now()->subDay($number)]);
     }
 }
开发者ID:annystartoo,项目名称:nfu-Laravel-01-23,代码行数:13,代码来源:PostTableSeeder.php

示例15: run

 public function run()
 {
     $faker = Faker::create();
     $cates = Category::lists('id')->toArray();
     for ($i = 1; $i <= 50; $i++) {
         Post::create(['title' => $faker->sentence(), 'summary' => $faker->paragraph(), 'category_id' => $faker->randomElement($cates), 'body' => $faker->text(10000), 'origin' => '', 'comment_count' => rand(0, 10), 'view_count' => rand(0, 200), 'favorite_count' => rand(0, 100), 'published' => rand(0, 1), 'slug' => 'post-' . $i]);
     }
 }
开发者ID:forehalo,项目名称:materialize-blog,代码行数:8,代码来源:DatabaseSeeder.php


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