本文整理汇总了PHP中app\Posts::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Posts::create方法的具体用法?PHP Posts::create怎么用?PHP Posts::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Posts
的用法示例。
在下文中一共展示了Posts::create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Requests\PostsFormRequest $request)
{
$input = $request->all();
$input['alias'] = HelperFunctions::str2url($request->title);
$input['user_id'] = \Auth::user()->id;
$post = Posts::create($input);
$categories_ids = [];
foreach ($input['categories_list'] as $value) {
$category = Categories::findOrNew($value);
if ($category->exists) {
array_push($categories_ids, $value);
} else {
$category->name = $value;
$category->save();
array_push($categories_ids, $category->id);
}
}
$post->categories()->attach($categories_ids);
$tags_ids = [];
foreach ($input['tags_list'] as $value) {
$tag = Tags::findOrNew($value);
if ($tag->exists) {
array_push($tags_ids, $value);
} else {
$tag->name = $value;
$tag->save();
array_push($tags_ids, $tag->id);
}
}
$post->tags()->attach($tags_ids);
\Session::flash('success', 'Post created');
return redirect('/');
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Requests\PostRequest $request)
{
$post = Posts::create($request->only(['title', 'post']));
if (!empty($request->file('image')) && $request->file('image')->isValid()) {
$destinationPath = public_path() . "/images/";
// upload path
$extension = $request->file('image')->getClientOriginalExtension();
// getting image extension
$fileName = $post->url . '.' . $extension;
// renameing image
$request->file('image')->move($destinationPath, $fileName);
// uploading file to given path
$post->image = $fileName;
}
$tags = [];
foreach ($this->getTags($request->input('tags')) as $tag) {
if (!empty($tag)) {
$isFind = Tags::where('name', $tag)->get()->count();
if ($isFind == 0) {
$tags[] = new Tags(['name' => $tag]);
} else {
$tags[] = Tags::where('name', $tag)->first();
}
}
}
$post->tags()->saveMany($tags);
return redirect()->route('admin.blog.edit', $post->id);
}
示例3: run
public function run()
{
//create post sides
DB::table('posts')->delete();
for ($i = 0; $i < 5; $i++) {
\App\Posts::create(['title' => "first post {$i}", 'description' => "this is a {$i} post description", "content" => "this is a {$i} post content"]);
}
}
示例4: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$faker = \Faker\Factory::create();
//Posts::truncate();
foreach (range(1, 10) as $index) {
$user = User::All()->random(1);
Posts::create(['author_id' => $user->id, 'title' => $faker->sentence(3), 'body' => $faker->text, 'slug' => $faker->slug(), 'active' => 1]);
}
}
示例5: run
public function run()
{
DB::table('posts')->delete();
Posts::create(array('author_id' => 1, 'slug' => 'post1', 'title' => 'post 1 title ', 'body' => 'post 1 body!', 'active' => true));
Posts::create(array('author_id' => 1, 'slug' => 'post2', 'title' => 'post 2 title', 'body' => 'post 2 body!', 'active' => true));
Posts::create(array('author_id' => 1, 'slug' => 'post3', 'title' => 'post 3 title ', 'body' => 'post 3 body!', 'active' => true));
Posts::create(array('author_id' => 1, 'slug' => 'post4', 'title' => 'post 4 title', 'body' => 'post 4 body!', 'active' => true));
Posts::create(array('author_id' => 1, 'slug' => 'post5', 'title' => 'post 5 title ', 'body' => 'post 5 body!', 'active' => true));
Posts::create(array('author_id' => 1, 'slug' => 'post6', 'title' => 'post 6 title', 'body' => 'post 6 body!', 'active' => true));
}
示例6: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$rules = array('title' => 'required|max:255|min:5|string', 'body' => 'required|max:2000|min:5|string', 'browser' => 'min:1|max:20');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('create')->withErrors($validator);
}
$data = array('title' => Purifier::clean($request->input('title')), 'body' => Purifier::clean($request->input('body')), 'image' => Purifier::clean($request->input('image')), 'ip' => $request->getClientIp(), 'browser' => Purifier::clean($request->input('browser')), 'country' => UserClients::getCountry($request->getClientIp()), 'date' => time());
Posts::create($data);
return Redirect::to('/');
}
示例7: run
public function run()
{
DB::table('posts')->delete();
Posts::create(array('author_id' => 1, 'slug' => 'post1', 'title' => 'title of post 1', 'body' => 'post 1 body!', 'active' => true));
}
示例8: postCreate
public function postCreate(Request $request)
{
$all = $request->all();
$validator = Validator::make($all, ['title' => 'required|max:255', 'content' => 'required', 'category_id' => 'required']);
if (isset($all['active'])) {
$all['active'] = true;
} else {
$all['active'] = false;
}
if ($validator->fails()) {
$page_title = 'Create Post';
$categories = Categories::all();
$tags = Tags::all();
$data = compact('page_title', 'categories', 'tags');
return view('posts.create', $data)->withErrors($validator->errors());
}
$user = Auth::user();
$markdown_content = $all['content'];
$html_content = $this->htmlMarkdownConvertor->convertMarkdownToHtml($markdown_content);
$post = Posts::create(['title' => $all['title'], 'content' => $html_content, 'markdown_content' => $markdown_content, 'active' => $all['active'], 'user_id' => $user->id, 'category_id' => $all['category_id']]);
$this->savePostsTags($all['tags'], $post->id);
return redirect(route('getPostPage'));
}