當前位置: 首頁>>代碼示例>>PHP>>正文


PHP News::create方法代碼示例

本文整理匯總了PHP中app\News::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP News::create方法的具體用法?PHP News::create怎麽用?PHP News::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\News的用法示例。


在下文中一共展示了News::create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: news

 public function news(Request $request)
 {
     if ($request->isMethod('POST')) {
         //            News::create($request->except('_token'));
         // read image from temporary file
         $file = $request->file('imagePrev');
         $img = Image::make($file->getRealPath());
         $nameFile = $file->getClientOriginalName();
         //          resize image
         $img->fit(263, 263);
         // save image
         $img->save("images/" . $nameFile);
         News::create(['text' => $request->input('editor1'), 'header' => $request->input('header'), 'picture' => "images/" . $nameFile]);
         //            switch ( $request->input('type') ) {
         //                case 'insert':
         //                    News::create($request->except('_token'));
         //                    break;
         //                case 'update':
         //                    News::find( $request->input('id') )->update([
         //                        'header' => $request->input('header'),
         //                        'text' => $request->input('editor1'),
         //                    ]);
         //                    break;
         //            }
     }
     if ($request->isMethod('GET')) {
         $item = News::find($request->input('remove'));
         if ($item) {
             $item->delete();
         }
     }
     $news = News::orderBy('created_at', 'DESC')->paginate(15);
     return view('admin/news', ['news' => $news]);
 }
開發者ID:GraninNikita,項目名稱:feo,代碼行數:34,代碼來源:AdminController.php

示例2: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(NewsRequest $request)
 {
     $input = Input::all();
     $tags = explode(',', $input['tags']);
     $slug = strtolower(implode('-', explode(' ', $input['title'])));
     $slug = str_replace('?', '', $slug);
     $slug = str_replace('/', '', $slug);
     $slug = str_replace('\\', '', $slug);
     if (News::where('slug', $slug)->first()) {
         return Response::json([0 => 'Deze titel is al gebruikt bij een ander artikel.'], HttpCode::Conflict);
     }
     $input['slug'] = $slug;
     $input['content'] = str_replace("\n", '', $input['content']);
     // remove line endings
     $input['content'] = str_replace("\r", '', $input['content']);
     // remove line endings
     $article = News::create($input);
     if (Auth::user()->hasOnePrivelege(['Moderator', 'Administrator'])) {
         $article->state = Input::get('publish') == "true" ? 1 : 0;
     } else {
         $article->state = 1;
     }
     foreach ($tags as $tag) {
         $article->tag($tag);
     }
     $article->save();
     return Response::json([0 => 'Nieuws artikel aangemaakt, klik <a href="/news/' . $slug . '">hier</a> om het te bekijken.'], HttpCode::Ok);
 }
開發者ID:VincentVanWijk,項目名稱:artotheek5,代碼行數:33,代碼來源:NewsController.php

示例3: run

 public function run()
 {
     $faker = Faker\Factory::create();
     for ($i = 0; $i < 20; $i++) {
         \App\News::create(['title' => $faker->unique()->sentence(4), 'date' => $faker->dateTimeThisCentury, 'published' => $faker->boolean(), 'text' => $faker->paragraph(5)]);
     }
 }
開發者ID:ntamvl,項目名稱:admin-3-demo,代碼行數:7,代碼來源:NewsSeeder.php

示例4: up

 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     $u = User::create(['first_name' => 'test', 'last_name' => 'test', 'email' => 'test@test.fr', 'level' => 1]);
     $u2 = User::create(['first_name' => 'test2', 'last_name' => 'test2', 'email' => 'test2@test.fr', 'level' => 1]);
     $u3 = User::create(['first_name' => 'test3', 'last_name' => 'test3', 'email' => 'test3@test.fr', 'level' => 2]);
     $e1 = Event::create(['name' => 'test event', 'user_id' => 3, 'slug' => 'test-event-1', 'date' => '2016-10-17', 'start' => '18:00:00', 'end' => '5:00:00']);
     $e2 = Event::create(['name' => 'test event', 'user_id' => 1, 'slug' => 'test-event-2', 'date' => '2016-08-22', 'start' => '19:00:00', 'end' => '5:00:00']);
     Event::create(['name' => 'test event', 'user_id' => 2, 'slug' => 'test-event-3', 'date' => '2017-01-07', 'start' => '18:00:00', 'end' => '5:00:00']);
     $p1 = Playlist::create(['name' => 'Playlist principale !']);
     $p2 = Playlist::create(['name' => 'The Playlist !']);
     $p3 = Playlist::create(['name' => 'Playlist secondaire']);
     Playlist::create(['name' => 'The Playlist !']);
     $p1->styles()->sync([1, 2, 3]);
     $p2->styles()->sync([1, 4]);
     $p3->styles()->sync([1, 3, 5, 7]);
     $e1->playlists()->sync([1, 3]);
     $e2->playlists()->sync([2]);
     Comment::create(['event_id' => 2, 'user_id' => 2, 'content' => 'Sooo goooood']);
     Comment::create(['event_id' => 3, 'user_id' => 2, 'content' => 'Sooo goooood :D']);
     Comment::create(['event_id' => 2, 'user_id' => 3, 'content' => 'Sooo goooood !!!']);
     Video::create(['url' => '7l48bfQuJeE', 'artist' => 'Chill Bump', 'name' => 'Lost In The Sound', 'tags' => 'chill bump lost in the sound']);
     Video::create(['url' => 'XxdPJvhQaMU', 'artist' => 'Chill Bump', 'name' => 'Water boycotter', 'tags' => 'chill bump water boycotter']);
     Video::create(['url' => 'kWXAYDQ_K7k', 'artist' => 'Chill Bump', 'name' => 'The Memo', 'tags' => 'chill bump the memo']);
     $pivot1 = $p1->videos()->sync([1, 3]);
     $pivot2 = $p2->videos()->sync([2]);
     $pivot3 = $p3->videos()->sync([1, 2, 3]);
     News::create(['title' => 'news test', 'content' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ', 'user_id' => 2, 'slug' => 'text-news-1']);
     News::create(['title' => 'news test 2', 'content' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ', 'user_id' => 3, 'slug' => 'text-news-2']);
     Article::create(['title' => 'Article test 1', 'content' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ', 'user_id' => 2, 'slug' => 'text-article-1']);
     Article::create(['title' => 'Article test 2', 'content' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ', 'user_id' => 3, 'slug' => 'text-article-2', 'event_id' => 2]);
 }
開發者ID:Techraav,項目名稱:djMaker,代碼行數:36,代碼來源:2017_06_10_032123_create_base_entries.php

示例5: store

 /**
  * @param \App\Http\Requests\CreateNewsRequest $request
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function store(CreateNewsRequest $request)
 {
     News::create($request->all());
     $news = News::orderBy('updated_at', 'desc')->get();
     session()->flash('flash_message', 'Je artikel is succesvol toegevoegd');
     return view('news.index', compact('news'));
 }
開發者ID:jordygroote,項目名稱:detoekomstapp,代碼行數:11,代碼來源:NewsController.php

示例6: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     $validation = Validator::make($input, News::$news_rules);
     if ($validation->passes()) {
         if (Input::get('types') == 'news') {
             $image = Input::file('coverImage');
             $extension = $image->getClientOriginalExtension();
             $filename = sha1(time() . time()) . ".{$extension}";
             $upload_success = \Image::make($image)->resize(\Config::get('image.news_image_width'), \Config::get('image.news_image_height'))->save(\Config::get('image.news_image') . $filename);
         } elseif (Input::get('types') == 'development') {
             $image = Input::file('coverImage');
             $extension = $image->getClientOriginalExtension();
             $filename = sha1(time() . time()) . ".{$extension}";
             $upload_success = \Image::make($image)->save(\Config::get('image.news_image') . $filename);
         }
         if ($upload_success) {
             News::create(array('types' => Input::get('types'), 'author' => Input::get('author'), 'content' => Input::get('content'), 'title' => Input::get('title'), 'coverImage' => $filename));
             return Redirect::to('admin/newsList');
         }
     } else {
         $error = $validation->errors()->first();
         return Redirect::to('news/create')->withInput(Input::all())->with(compact('error'));
     }
 }
開發者ID:klokand,項目名稱:JulySite,代碼行數:30,代碼來源:NewsController.php

示例7: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 30) as $index) {
         News::create(['user_id' => '1', 'title' => $faker->sentence(4), 'url' => $faker->slug(3), 'content' => $faker->paragraphs(8, true), 'metatitle' => '', 'metakeywords' => '', 'metadesc' => '', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now(), 'published_at' => Carbon::now()]);
     }
 }
開發者ID:vowsdesrat,項目名稱:laravel,代碼行數:12,代碼來源:NewsTableSeeder.php

示例8: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('cars')->delete();
     for ($i = 0; $i < count($this->items); $i++) {
         $row = array_combine(['title', 'text', 'image'], $this->items[$i]) + ['published_at' => Carbon::now()];
         News::create($row);
     }
 }
開發者ID:jambik,項目名稱:sellmecar,代碼行數:13,代碼來源:NewsTableSeeder.php

示例9: run

 /**
  * Copies over all the news from the ATLauncher's API into our database.
  *
  * @return void
  */
 public function run()
 {
     DB::table('news')->delete();
     $atl_news = json_decode(file_get_contents('https://api.atlauncher.com/v1/news'))->data;
     foreach ($atl_news as $news) {
         News::create(array('title' => $news->title, 'comments' => $news->comments, 'link' => $news->link, 'published_at' => $news->published_at, 'content' => $news->content));
     }
 }
開發者ID:jamierocks,項目名稱:Launcher-API,代碼行數:13,代碼來源:NewsTableSeeder.php

示例10: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $news = Input::all();
     if (!$news['published_at']) {
         $news['published_at'] = Carbon::now();
     }
     News::create($news);
     return redirect('/')->withSuccess("'Новина додана успішно!'");
 }
開發者ID:Andrew261,項目名稱:filolog,代碼行數:14,代碼來源:NewsController.php

示例11: insert

 public function insert()
 {
     $entry = array('id' => Input::get('id'), 'name' => strtolower(Input::get('name')), 'title' => Input::get('title'), 'body' => Input::get('body'), 'image' => Input::get('image'), 'author_id' => Input::get('author_id'));
     if (isset($entry)) {
         News::create($entry);
         return \Redirect::route('news')->with('success', $entry['title'] . ' added succesfully!');
     } else {
         return \Redirect::route('add_news', array($entry['id']))->with('error', 'Failed to add, invalid credentials.');
     }
 }
開發者ID:VertexDezign,項目名稱:VertexDezign,代碼行數:10,代碼來源:BackendNewsController.php

示例12: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['title' => 'required']);
     $input = $request->all();
     $input['published_at'] = $input['published_at'] ?: Carbon::now();
     $item = News::create($input);
     $item->saveImage($item, $request);
     Flash::success("Запись - {$item->id} сохранена");
     return redirect(route('admin.news.index'));
 }
開發者ID:jambik,項目名稱:sellmecar,代碼行數:16,代碼來源:NewsController.php

示例13: create

 public function create()
 {
     $aNewsData = Input::get('news');
     $validator = Validator::make($aNewsData, ['title' => 'required|max:255', 'content' => 'required', 'state' => 'in:created,visible,deleted']);
     if ($validator->fails()) {
         $aRet = ['success' => 'false', 'errors' => $validator->errors()];
     } elseif ($oNews = News::create($aNewsData)) {
         $aRet = ['success' => 'true'];
     } else {
         $aRet = ['success' => 'false'];
     }
     return response()->json($aRet);
 }
開發者ID:kaeku,項目名稱:openzou,代碼行數:13,代碼來源:NewsServiceController.php

示例14: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \App\Http\Requests\NewsRequest $request
  * @return \Illuminate\Http\Response
  */
 public function store(Requests\NewsRequest $request)
 {
     $departmentId = auth()->user()->department_id;
     if ($request->has('department_id') && $this->systemAdmin) {
         $departmentId = $request->get('department_id');
     }
     DB::transaction(function () use($departmentId, $request) {
         $news = News::create(['department_id' => $departmentId, 'active' => $request->get('active'), 'sort' => $request->get('sort')]);
         $langs = [];
         foreach (LaravelLocalization::getSupportedLocales() as $short => $locale) {
             $langs[] = ['lang_id' => dbTrans($short), 'title' => $request->get('title_' . $short), 'description' => $request->get('description_' . $short)];
         }
         $news->langs()->createMany($langs);
     });
     return redirect(action('Admin\\NewsController@index'))->with('success', 'saved');
 }
開發者ID:Tisho84,項目名稱:conference,代碼行數:22,代碼來源:NewsController.php

示例15: store

 public function store(Request $request)
 {
     //dd($request->all());
     $user = $this->user;
     $this->validate($request, ['title' => 'required', 'content' => 'required', 'status' => 'required | in:0,1']);
     if ($request->hasFile('image')) {
         $this->validate($request, ['image' => 'mimes:jpeg,jpg,bmp,png | max:1024']);
         $imageName = $this->uploadImage($request->file('image'));
     } else {
         $imageName = null;
     }
     $news = News::create(['title' => $request->input('title'), 'content' => $request->input('content'), 'status' => $request->input('status'), 'user_id' => $user->id, 'image' => $imageName]);
     /*
      * Register Tags
      */
     $selected = $this->registerTags($request);
     //آی دی های تگ های جدید
     $news->tags()->sync($selected);
     Flash::success(trans('messages.newsCreated'));
     return redirect()->back();
 }
開發者ID:slifer2015,項目名稱:tarabar,代碼行數:21,代碼來源:NewsController.php


注:本文中的app\News::create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。