/**
  * 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('/');
 }
Esempio n. 2
0
 /**
  * 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);
 }
 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"]);
     }
 }
 /**
  * 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]);
     }
 }
 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));
 }
 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));
 }
 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'));
 }
Esempio n. 8
-1
 /**
  * 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('/');
 }