/**
  * Store a newly created resource in storage.
  *
  * @param  Request $request
  * @return Response
  */
 public function store(CategoryRequest $request)
 {
     //@tosdo Attribute Save
     $category = Category::create($request->all());
     if ($request->file('file') != "") {
         $category->image_path = $this->uploadImage($request->file('file'), $for = 'categories');
     }
     //Saving Attributes
     $attributes = $request->get('attribute');
     $this->saveAttribute($attributes, $category->id);
     $category->slug = str_slug($request->get('name'));
     //update File Path and Slug
     $category->save();
     return redirect('/admin/category');
 }
Exemplo n.º 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function postEdit(CategoryRequest $request, $id)
 {
     $object = Object::find($id);
     if ($request->parent_id) {
         $object->parent_id = $request->parent_id;
     } else {
         $object->parent_id = null;
     }
     $object->author_id = Auth::user()->id;
     $object->name = preg_replace('[ ]', '-', strtolower($request->name));
     $object->title = $request->title;
     $object->content = $request->content;
     $object->excerpt = $request->excerpt;
     if ($request->hasFile('featuredImage')) {
         $file = $request->file('featuredImage');
         $filename = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension();
         $mimeType = $file->getMimeType();
         $destinationPath = public_path() . '/uploads/';
         $newfileName = sha1($filename . time());
         $picture = $newfileName . '.' . $extension;
         $request->file('featuredImage')->move($destinationPath, $picture);
         if ($imageObject = addImage($object, $destinationPath, $picture, $filename, $newfileName, $extension, $mimeType, '_featured_image')) {
         }
     }
     if ($request->hasFile('contentImage')) {
         $file = $request->file('contentImage');
         $filename = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension();
         $mimeType = $file->getMimeType();
         $destinationPath = public_path() . '/uploads/';
         $newfileName = sha1($filename . time());
         $picture = $newfileName . '.' . $extension;
         $request->file('contentImage')->move($destinationPath, $picture);
         if ($imageObject = addImage($object, $destinationPath, $picture, $filename, $newfileName, $extension, $mimeType, '_content_image')) {
         }
     }
     $object->save();
     $object->setValue('_tooltip', $request->toolTip);
     return redirect('admin/categories')->with('message', 'Object saved successfully');
 }
Exemplo n.º 3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function postEdit(CategoryRequest $request, $id)
 {
     $object = Object::find($id);
     if ($request->parent_id) {
         $object->parent_id = $request->parent_id;
     } else {
         $object->parent_id = null;
     }
     $object->author_id = Auth::user()->id;
     $object->name = preg_replace('[ ]', '-', strtolower($request->name));
     $object->title = $request->title;
     $object->content = $request->content;
     $object->excerpt = $request->excerpt;
     if ($request->hasFile('featuredImage')) {
         $file = $request->file('featuredImage');
         $filename = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension();
         $mimeType = $file->getMimeType();
         $destinationPath = public_path() . '/uploads/';
         $newfileName = sha1($filename . time());
         $picture = $newfileName . '.' . $extension;
         $request->file('featuredImage')->move($destinationPath, $picture);
         if ($imageObject = addImage($object, $destinationPath, $picture, $filename, $newfileName, $extension, $mimeType, '_featured_image')) {
         }
     }
     if ($request->hasFile('contentImage')) {
         $file = $request->file('contentImage');
         $filename = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension();
         $mimeType = $file->getMimeType();
         $destinationPath = public_path() . '/uploads/';
         $newfileName = sha1($filename . time());
         $picture = $newfileName . '.' . $extension;
         $request->file('contentImage')->move($destinationPath, $picture);
         if ($imageObject = addImage($object, $destinationPath, $picture, $filename, $newfileName, $extension, $mimeType, '_content_image')) {
         }
     }
     if ($request->get('score')) {
         $object->score = $request->get('score');
     }
     $object->url = $request->get('url', '');
     if ($request->get('target')) {
         $object->target = '_blank';
     } else {
         $object->target = '_self';
     }
     $object->save();
     $keywords = $request->get('keywords', false);
     $keywords = trim($keywords);
     if ($keywords) {
         $keywords = explode(',', $keywords);
         $keywords = array_map('trim', $keywords);
         $originalKeywords = $object->keywords;
         foreach ($originalKeywords as $item) {
             if (!in_array($item->content, $keywords)) {
                 $item->delete();
             } else {
                 unset($keywords[array_search($item->content, $keywords)]);
             }
         }
         foreach ($keywords as $item) {
             if (trim($item) == '') {
                 continue;
             }
             $object->keywords()->create(['content' => $item]);
         }
     } else {
         $object->keywords()->delete();
     }
     $object->setValue('_tooltip', $request->toolTip);
     return redirect('admin/categories')->with('message', 'Object saved successfully');
 }