本文整理汇总了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]);
}
示例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);
}
示例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)]);
}
}
示例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]);
}
示例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'));
}
示例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'));
}
}
示例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()]);
}
}
示例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);
}
}
示例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));
}
}
示例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("'Новина додана успішно!'");
}
示例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.');
}
}
示例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'));
}
示例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);
}
示例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');
}
示例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();
}