Esempio n. 1
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     $favicon = Settings::getSettings()['favicon'];
     $logo = Settings::getSettings()['logo'];
     $parent_categories = Category::getCategoriesByPublish(1, 0, 1);
     View::share('favicon', $favicon);
     View::share('logo', $logo);
     View::share('parent_categories', $parent_categories);
 }
Esempio n. 2
0
 /**
  * Edit post
  *
  * @param Request $request
  * @param int $id
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
  */
 public function edit(Request $request, $id = 0)
 {
     $post = Post::getPostById($id);
     if (empty($post)) {
         return redirect()->back();
     } else {
         if ($request->isMethod("post")) {
             $rules = ["title" => "required", "alias" => "required|unique:posts,alias," . $id, "content" => "required", 'image' => 'mimes:jpeg,jpg,png'];
             Validator::make($request->all(), $rules)->validate();
             $post->title = $request->input("title");
             $post->alias = $request->input("alias");
             $post->content = $request->input("content");
             $post->meta_keys = $request->input("meta_keys");
             $post->meta_desc = $request->input("meta_desc");
             if (!empty($request->file("image"))) {
                 if (!empty($post->image)) {
                     if (Storage::exists('uploads/' . $post->image) && Storage::exists('uploads/fb-' . $post->image)) {
                         Storage::delete('uploads/' . $post->image, 'uploads/fb-' . $post->image);
                     }
                 }
                 $generated_string = str_random(32);
                 $file = $request->file("image")->store('uploads');
                 $new_file = $generated_string . '.' . $request->file("image")->getClientOriginalExtension();
                 Storage::move($file, 'uploads/' . $new_file);
                 $img = Image::make($request->file('image'));
                 $img->crop(200, 200);
                 $img->save(storage_path('app/public/uploads/' . $new_file));
                 $img = Image::make($request->file('image'));
                 $img->resize(600, 315);
                 $img->save(storage_path('app/public/uploads/fb-' . $new_file));
                 $post->image = $new_file;
             }
             if ($request->has("category")) {
                 $post->category_id = $request->input("category");
             }
             $post->publish = $request->has("publish");
             $post->save();
             $new_tags = [];
             if ($request->has("tags")) {
                 $tags = $request->input("tags");
                 foreach ($tags as $tag) {
                     array_push($new_tags, $tag);
                 }
             }
             $post->tags()->sync($new_tags);
             return redirect()->route('posts');
         } else {
             $categories = Category::getCategoriesByPublish();
             $tags = Tag::getTags();
             return view("site.post.edit", compact("post", "categories", "tags"));
         }
     }
 }