protected function filter_project_input()
 {
     $input = Input::all();
     foreach (['profile', 'cover'] as $name) {
         if (Input::file($name) && Input::file($name)->isValid()) {
             $res = \Cloudinary\Uploader::upload(Input::file($name)->getRealPath());
             if ($res && isset($res['public_id'])) {
                 $media = Media::create(['public_id' => $res['public_id']]);
                 $input[$name . '_media_id'] = $media->id;
             }
             unset($input[$name]);
         }
     }
     return $input;
 }
 public function run()
 {
     if (class_exists('Faker\\Factory')) {
         $faker = Faker\Factory::create();
         $images = ['img/eusthenopteron_foordi.jpg', 'img/iridotriton_hechti.jpg', 'img/sipalocyon_sp.jpg', 'img/teinolophos_trusleri.jpg'];
         $scans = Scan::all()->all();
         $mediaTypes = MediaType::all()->all();
         foreach ($scans as $scan) {
             $count = $faker->randomDigit;
             for ($i = 1; $i <= $count; $i++) {
                 Media::create(['filePath' => '/' . $faker->word, 'fileName' => $faker->word . $faker->randomNumber(2) . '.' . $faker->randomElement(['stl', 'vgl', 'mov', 'dct']), 'fileUrl' => $faker->randomElement($images), 'scanId' => $scan->id, 'mediaTypeId' => $faker->randomElement($mediaTypes)->id]);
             }
         }
     }
 }
Beispiel #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $formdata = $request->all();
     $validator = Validator::make($formdata, Media::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $absolute_path = public_path() . '/uploads/media';
     $folderPath = '/uploads/media/';
     if (!file_exists($absolute_path)) {
         try {
             if (!mkdir($absolute_path)) {
                 die('could not create folder');
             }
         } catch (Exception $e) {
             die('could not create folder');
         }
     }
     if (!is_null($request->file('filename'))) {
         $photofile = $request->file('filename');
         $filename = time() . '-' . $photofile->getClientOriginalName();
         $photofile->move(public_path() . '/uploads/media/', $filename);
         $photo = Image::make(public_path() . '/uploads/media/' . $filename);
         // $photo = Image::make($photofile);
         $photo->backup();
         $photo->fit(150, 100, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         });
         $thumb = public_path() . '/uploads/media/small-' . $filename;
         $photo->save($thumb);
         $photo->reset();
         $photo->fit(550, 300, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         });
         $thumb = public_path() . '/uploads/media/medium-' . $filename;
         $photo->save($thumb);
         $photo->reset();
         //replacing original
         $photo->fit(880, 450, function ($constraint) {
             $constraint->aspectRatio();
             // $constraint->upsize();
         });
         $photo->save(public_path() . '/uploads/media/' . $filename);
         $formdata['filename'] = $filename;
         $formdata['filepath'] = "/uploads/media/";
     }
     Media::create($formdata);
     return Redirect::route('media.admin');
 }