コード例 #1
0
ファイル: ObjectController.php プロジェクト: arielcrm/Jini
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postCreate(ObjectRequest $request)
 {
     $object = new Object();
     $object->author_id = Auth::user()->id;
     $object->type = $request->_object_type;
     $object->name = str_replace(' ', '-', $request->title);
     $object->title = $request->title;
     $object->status = 'published';
     $object->guid = Hash::getUniqueId();
     $object->save();
     foreach (array_keys($_POST) as $key) {
         if (substr($key, 0, 7) == '_field_') {
             $object->setValue($key, $request->input($key));
         }
     }
     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')) {
         }
     }
     return redirect('admin/object-types')->with('message', 'Type saved successfully');
 }