本文整理汇总了PHP中app\Article::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::create方法的具体用法?PHP Article::create怎么用?PHP Article::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Article
的用法示例。
在下文中一共展示了Article::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$faker = Faker\Factory::create();
for ($i = 0; $i < 10; ++$i) {
Article::create(['title' => $faker->sentence, 'content' => implode('', $faker->sentences(4))]);
}
}
示例2: postPost
public function postPost(Request $request)
{
$input = $request->all();
$rules = ['title' => ['max:20', 'required'], 'content' => ['min:10', 'required']];
$validator = Validator::make($input, $rules);
$returnInf = [];
if ($validator->fails()) {
$messages = $validator->messages();
foreach ($array_dot($messages->toArray) as $value) {
array_push($returnInf, $value);
}
Session::flash('operationResult', 'am-alert-warning');
Session::flash('returnInf', $returnInf);
return redirect()->back()->withInput(Request::flash());
} else {
$article = Article::create(['title' => $input['title'], 'content' => Common::encodeTopicContent($input['content']), 'node_id' => $input['node_id'], 'user_id' => $input['user_id']]);
if ($article->id > 0) {
array_push($returnInf, '发帖成功');
Session::flash('operationResult', 'am-alert-success');
Node::find($input['node_id'])->increment('article_count');
User::find($input['user_id'])->increment('article_count');
} else {
array_push($returnInf, '我们的数据库出问题啦,请稍后再试=。=');
Session::flash('operationResult', 'am-alert-warning');
}
}
Session::flash('returnInf', $returnInf);
return redirect()->back();
}
示例3: store
public function store(ArticleFormRequest $request)
{
$title = $request->input('title');
$content = $request->input('content');
Article::create(['title' => $title, 'content' => $content]);
return redirect()->route('article.index');
}
示例4: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('articles')->delete();
for ($i = 0; $i < 10; $i++) {
Article::create(['title' => '文章00' . $i, 'slug' => '概述00' . $i, 'body' => '文章00' . $i, 'user_id' => 15]);
}
}
示例5: store
/**
* Function for storing a new blog article.
*
* @param $request
* @param ArticleRequest $request
* @return Redirect
*/
public function store(ArticleRequest $request)
{
if ($request->has('slug')) {
$request['slug'] = str_slug($request['slug'], "_");
} else {
$request['slug'] = str_slug($request['title'], "_");
}
$today = Carbon::today()->format('Y') . '/' . Carbon::today()->format('M') . '/' . Carbon::today()->format('d');
$uploadPath = base_path() . '/public/img/uploads/' . $today;
$article = Article::create($request->all());
// TODO: Refine into two seperate actions //
if (!empty($request['cover-image']) || !empty($request['cover-image'])) {
$SmallImageName = '/img/uploads/' . $today . '/' . $request['slug'] . '_sml' . '.' . $request->file('listing-image')->getClientOriginalExtension();
$coverImageName = '/img/uploads/' . $today . '/' . $request['slug'] . '_cover' . '.' . $request->file('cover-image')->getClientOriginalExtension();
$article['imgfull'] = $coverImageName;
$article['imgsml'] = $SmallImageName;
}
$article['page_code'] = str_random(16);
$article['author'] = Auth::user()->id;
$article['category'] = $request['category'];
// TODO:: Preform a check to see if this Category Exists //
$article['published'] = Carbon::parse($request['published']);
// TODO:: Add a time to publish field //
$article->save();
if (!empty($request['cover-image']) || !empty($request['cover-image'])) {
$request->file('listing-image')->move($uploadPath, $SmallImageName);
$request->file('cover-image')->move($uploadPath, $coverImageName);
}
return redirect('blog/' . $request->slug);
}
示例6: store
public function store(Request $request)
{
$this->validate($request, ['title' => 'required', 'body' => 'required']);
$input = $request->all();
Article::create($input);
return redirect('articles');
}
示例7: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$generator = \Faker\Factory::create('vi_VN');
$articleCategories = ['Thông tin', 'Bài viết nỗi bật'];
foreach ($articleCategories as $key => $value) {
$articleCategory = ArticleCategory::create(['key' => Common::createKeyURL($value), 'parent_id' => 0, 'priority' => 0, 'is_publish' => 1, 'created_by' => 'phantsang', 'updated_by' => 'phantsang']);
ArticleCategoryTranslation::create(['article_category_id' => $articleCategory->id, 'locale' => 'vi', 'name' => $value, 'summary' => $value, 'meta_description' => $value, 'meta_keywords' => $value]);
}
$articles = ['Giới thiệu', 'Dịch vụ của chúng tôi', 'Tại sao chọn chúng tôi'];
foreach ($articles as $key => $item) {
$article = Article::create(['key' => Common::createKeyURL($item), 'priority' => 0, 'is_publish' => 1, 'created_by' => 'phantsang', 'updated_by' => 'phantsang']);
ArticleTranslation::create(['article_id' => $article->id, 'locale' => 'vi', 'name' => $item, 'summary' => $generator->text($maxNbChars = 200), 'content' => $generator->text, 'meta_description' => $generator->text($maxNbChars = 200), 'meta_keywords' => $generator->text($maxNbChars = 200)]);
Attachment::create(['entry_id' => $article->id, 'table_name' => 'articles', 'path' => '/uploads/notfound.jpg', 'priority' => 0, 'is_publish' => 1]);
}
// BÀI VIẾT THÔNG TIN
$articleCategory = ArticleCategory::findByKey('thong-tin')->first()->id;
if (!is_null($articleCategory) && count($articleCategory) > 0) {
for ($i = 0; $i < 10; $i++) {
$name = $generator->sentence($nbWords = 6);
$article = Article::create(['key' => Common::createKeyURL($name), 'priority' => 0, 'is_publish' => 1, 'created_by' => 'phantsang', 'updated_by' => 'phantsang']);
ArticleTranslation::create(['article_id' => $article->id, 'locale' => 'vi', 'name' => $name, 'summary' => $generator->text($maxNbChars = 200), 'content' => $generator->text, 'meta_description' => $generator->text($maxNbChars = 200), 'meta_keywords' => $generator->text($maxNbChars = 200)]);
/*
Attachment::create([
'entry_id' => $article->id,
'table_name' => 'articles',
//'path' => $generator->imageUrl($width = 780, $height = 546),
'path' => '/uploads/notfound.jpg',
'priority' => 0,
'is_publish' => 1
]);
*/
$article->categories()->attach($articleCategory);
}
}
}
示例8: run
public function run()
{
$feeder = Feeder::all()->first();
$feederId = $feeder->id;
DB::table('articles')->delete();
Article::create(array('title' => 'Milano. La stella e le emozioni sono solo Innocenti Evasioni', 'url' => 'http://www.scattidigusto.it/2016/02/12/ristoranti-milano-innocenti-evasioni/', 'feeder_id' => $feederId));
}
示例9: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$faker = Faker\Factory::create();
for ($i = 0; $i < 20; $i++) {
Article::create(['title' => $faker->sentence, 'content' => $faker->sentence(20)]);
}
}
示例10: store2
public function store2(Request $request)
{
$this->validate($request, ["body" => "required", "title" => "required|min:3", "published_at" => "required"]);
$input = $request->all();
Article::create(["title" => $input->title, "body" => $input->body, "published_at" => $input->published_at]);
return redirect("articles");
}
示例11: store
public function store(ArticleRequest $request)
{
$article = Article::create($request->all());
$article->tags()->attach($request->input('tag_list'));
flash()->success("Your article has been created");
return redirect('articles');
}
示例12: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$input = Request::all();
Article::create($input);
//denne metoden lagrer i databasen
return redirect('articles');
}
示例13: create
/**
* article store.
*
* @return \Illuminate\Http\Response
*/
public function create(Request $request)
{
$data = $request->all();
// dd($data);
Article::create($data);
return response()->json(['message' => '添加成功'], 201);
}
示例14: store
public function store(ArticleFormRequest $request)
{
$title = $request->input('title');
$content = $request->input('content');
Article::create(['title' => $title, 'content' => $content, 'username' => auth()->user()->name]);
return redirect()->route('get.articles');
}
示例15: run
public function run()
{
DB::table('articles')->delete();
for ($i = 0; $i < 10; $i++) {
Article::create(['title' => 'Title ' . $i, 'slug' => 'first-page', 'body' => 'Body ' . $i, 'body' => 'Body ' . $i, 'image' => 'image ' . $i, 'user_id' => 1]);
}
}