本文整理汇总了PHP中app\models\News::create方法的典型用法代码示例。如果您正苦于以下问题:PHP News::create方法的具体用法?PHP News::create怎么用?PHP News::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\News
的用法示例。
在下文中一共展示了News::create方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postNew
public function postNew(Request $request)
{
// dd($request);
$this->validate($request, News::$rules);
News::create($request->all());
return redirect()->action('NewsController@getIndex');
}
示例2: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$newses = [['title' => 'МИД Британии: Совет Безопасности ООН обсудит ответные меры на запуск ракеты КНДР', 'text' => 'КНДР в воскресенье запустила баллистическую ракету с космодрома "Сохэ". Глава МИД Великобритании назвал запуск "провокационным" и отметил, что Совет Безопасности ООН согласует коллективный ответ на испытания.'], ['title' => 'Китай обеспокоен возможным размещением ПРО США в Южной Корее', 'text' => 'Во внешнеполитическом ведомстве КНР подчеркнули, что позиция Китая по вопросу ПРО последовательна и ясна. Там отметили, что все страны, стремясь обеспечить свою безопасность, должны иметь в виду интересы в сфере безопасности других стран.']];
foreach ($newses as $news) {
\App\Models\News::create($news);
}
}
示例3: create
/**
* 创建
*
* @param array $input
* @return News
* @throws GeneralException
*/
public function create(array $input)
{
if ($id = News::create($input)) {
return $id;
}
throw new GeneralException('There was a problem creating this news. Please try again.');
}
示例4: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('news')->delete();
for ($i = 0; $i < 100; $i++) {
News::create(['title' => 'Title ' . $i, 'meta_description' => 'meta desc ' . $i, 'views' => '1000', 'content' => 'Body ' . $i, 'user_id' => 1]);
}
}
示例5: store
/**
* Store a newly created News in storage.
*
* @param CreateNewsRequest $request
*
* @return Response
*/
public function store(CreateNewsRequest $request)
{
$input = $request->all();
$news = News::create($input);
Flash::message('News saved successfully.');
return redirect(route('news.index'));
}
示例6: run
public function run()
{
// clear table
News::truncate();
News::create(['title' => 'Entry 1 Title', 'date' => Carbon::now(), 'published' => 1, 'text' => 'Entry 1 Text', 'photo' => '']);
News::create(['title' => 'Entry 2 Title', 'date' => Carbon::now(), 'published' => 1, 'text' => 'Entry 2 Text', 'photo' => '']);
News::create(['title' => 'Entry 3 Title', 'date' => Carbon::now(), 'published' => 1, 'text' => 'Entry 3 Text', 'photo' => '']);
News::create(['title' => 'Entry 4 Title', 'date' => Carbon::now(), 'published' => 1, 'text' => 'Entry 4 Text', 'photo' => '']);
}
示例7: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$newsFields = $this->doValidation($request, News::getValidatorRules());
$newsFields["Story_Date"] = Carbon::parse($newsFields["Story_Date"]);
$newsFields['Date_Created'] = Carbon::now();
$newsModel = News::create($newsFields);
$this->saveObjectRelation($request, $newsModel);
return redirect(route('admin.news.index'))->with('flash', 'The News was created');
}
示例8: run
public function run()
{
News::truncate();
$faker = Faker\Factory::create();
$authorIds = User::lists('id');
for ($i = 0; $i < 10; $i++) {
News::create(['title' => $faker->word, 'desc' => $faker->sentence, 'image_url' => $faker->imageUrl($width = 640, $height = 480), 'share_url' => $faker->url, 'status' => $faker->randomElement(array(0, 1)), 'author_id' => $faker->randomElement($authorIds)]);
}
}
示例9: actionCreate
public function actionCreate()
{
$model = new News();
$login = new login();
$imgLoad = new imgLoad();
if (Yii::$app->user->identity->level > 1) {
if ($model->load(Yii::$app->request->post()) && $model->create()) {
if ($imgLoad->load(Yii::$app->request->post())) {
if ($imgLoad->file = UploadedFile::getInstance($imgLoad, 'file')) {
$imgLoad->img_load($model->id);
$model->save_id_img($imgLoad->id);
}
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['login' => $login, 'model' => $model, 'imgLoad' => $imgLoad]);
}
}
}
示例10: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$formdata = $request->all();
$validator = Validator::make($formdata, News::$rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
$absolute_path = public_path() . '/uploads/news';
$folderPath = '/uploads/news/';
if (!file_exists($absolute_path)) {
try {
if (!mkdir($absolute_path)) {
die('could not create folder');
}
} catch (Exception $e) {
die('could not create folder');
}
}
if (!is_null($request->file('filename'))) {
$photofile = $request->file('filename');
$filename = time() . '-' . $photofile->getClientOriginalName();
$photofile->move(public_path() . '/uploads/news/', $filename);
$photo = Image::make(public_path() . '/uploads/news/' . $filename);
// $photo = Image::make($photofile);
$photo->backup();
$photo->fit(150, 100, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
$thumb = public_path() . '/uploads/news/small-' . $filename;
$photo->save($thumb);
$photo->reset();
$photo->fit(550, 300, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
$thumb = public_path() . '/uploads/news/medium-' . $filename;
$photo->save($thumb);
$photo->reset();
//replacing original
$photo->fit(880, 450, function ($constraint) {
$constraint->aspectRatio();
// $constraint->upsize();
});
$photo->save(public_path() . '/uploads/news/' . $filename);
$formdata['filename'] = $filename;
$formdata['filepath'] = "/uploads/news/";
}
News::create($formdata);
return Redirect::route('news.admin');
}
示例11: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('news')->delete();
News::create(['author_id' => 1, 'app_id' => 'koala', 'content' => '欢迎访问西邮Linux兴趣小组内部交流平台Koala(考拉)。目前系统处于内测阶段,上线的功能有:应用,消息,管理。
欢迎大家积极参与测试,我们期待你的反馈。', 'topic' => 'Koala']);
}
示例12: store
/**
* Store a newly created News in storage.
*
* @param NewsRequest $request
* @return Response
*/
public function store(NewsRequest $request)
{
News::create(['title' => $request->title, 'published_at' => $request->published_at, 'description' => e($this->htmlEditor->parseHtml($request->description))]);
Flash::success('News created successfully.');
return redirect('/admin/news');
}