/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $experiments = Experiment::active()->get();
     $goals = array_unique(Goal::active()->orderBy('name')->lists('name')->toArray());
     $columns = array_merge(['Experiment', 'Visitors', 'Engagement'], array_map('ucfirst', $goals));
     $writer = new Writer(new SplTempFileObject());
     $writer->insertOne($columns);
     foreach ($experiments as $experiment) {
         $engagement = $experiment->visitors ? $experiment->engagement / $experiment->visitors * 100 : 0;
         $row = [$experiment->name, $experiment->visitors, number_format($engagement, 2) . " % (" . $experiment->engagement . ")"];
         $results = $experiment->goals()->lists('count', 'name');
         foreach ($goals as $column) {
             $count = array_get($results, $column, 0);
             $percentage = $experiment->visitors ? $count / $experiment->visitors * 100 : 0;
             $row[] = number_format($percentage, 2) . " % ({$count})";
         }
         $writer->insertOne($row);
     }
     $output = (string) $writer;
     if ($file = $this->argument('file')) {
         $this->info("Creating {$file}");
         File::put($file, $output);
     } else {
         $this->line($output);
     }
 }
 /**
  * @return string
  */
 public function getRename()
 {
     $old_name = Input::get('file');
     $new_name = Input::get('new_name');
     $file_path = parent::getPath('directory');
     $thumb_path = parent::getPath('thumb');
     $old_file = $file_path . $old_name;
     if (!File::isDirectory($old_file)) {
         $extension = File::extension($old_file);
         $new_name = str_replace('.' . $extension, '', $new_name) . '.' . $extension;
     }
     $new_file = $file_path . $new_name;
     if (File::exists($new_file)) {
         return Lang::get('laravel-filemanager::lfm.error-rename');
     }
     if (File::isDirectory($old_file)) {
         File::move($old_file, $new_file);
         return 'OK';
     }
     File::move($old_file, $new_file);
     if ('Images' === $this->file_type) {
         File::move($thumb_path . $old_name, $thumb_path . $new_name);
     }
     return 'OK';
 }
 public function saveCroppedImage(Request $request, $slider_title = "")
 {
     $file = $request->file('slider_img');
     if ($file && isset($_FILES["slider_img"]["tmp_name"])) {
         try {
             $slider_img_x = $_POST['x'];
             $slider_img_y = $_POST['y'];
             $slider_img_w = $_POST['w'];
             $slider_img_h = $_POST['h'];
             $display_w = $_POST['display_w'];
             $file_path = $file->getPathname();
             $orig_w = getimagesize($_FILES["slider_img"]["tmp_name"])[0];
             $ratio = $orig_w / $display_w;
             $fileUploadDir = 'files/uploads/';
             $fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension();
             if (File::exists($fileUploadDir . $fileName)) {
                 $fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension();
             }
             $img = \Img::make($file_path)->crop((int) ($slider_img_w * $ratio), (int) ($slider_img_h * $ratio), (int) ($slider_img_x * $ratio), (int) ($slider_img_y * $ratio));
             $img = $img->resize(300, 300);
             $tmpFile = $fileUploadDir . "tmp_slider_img" . time();
             $img->save($tmpFile);
             //merge two images to one
             $this->merge('img/deze.png', $tmpFile, $fileUploadDir . $fileName, $slider_title, $request);
             //delete tmp file
             File::delete($tmpFile);
             return $fileName;
         } catch (Exception $e) {
             return false;
         }
     }
     return false;
 }
 protected function saveFileContents($fileName, $content)
 {
     $bytesWritten = File::put($fileName, $content);
     if ($bytesWritten === false) {
         dd('Error writing file: ' . $fileName);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['file' => 'mimes:pdf', 'name' => 'max:100']);
     if ($validator->fails()) {
         return redirect()->back()->withErrors(['file' => 'ไฟล์จะต้องเป็น .pdf เท่านั้น'])->withInput();
     }
     $riskManagements = RiskManagement::where('year', '=', $request->get('year'))->where('period', '=', $request->get('period'))->get();
     if (sizeof($riskManagements) > 0) {
         foreach ($riskManagements as $riskManagement) {
             $filename = base_path() . '/public/uploads/Risk-Management/' . $request->get('year') . '/' . $request->get('period') . '/' . $riskManagement->file_path;
             if (File::exists($filename)) {
                 File::delete($filename);
             }
             RiskManagement::destroy($riskManagement->id);
         }
     }
     if (Input::file('file')->isValid()) {
         $filePath = date('Ymd_His') . '.pdf';
         if (Input::file('file')->move(base_path() . '/public/uploads/Risk-Management/' . $request->get('year') . '/' . $request->get('period'), $filePath)) {
             //example of delete exist file
             $riskManagement = new RiskManagement();
             $riskManagement->file_path = $filePath;
             $riskManagement->year = $request->get('year');
             $riskManagement->period = $request->get('period');
             $riskManagement->save();
             return redirect('/admin/management');
         } else {
             return redirect()->back()->withErrors(['error_message' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']);
         }
     }
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     Schema::drop('pictures');
     //delete everything inside the images directory
     $path = public_path() . '/content/images/';
     File::deleteDirectory($path, true);
 }
Example #7
0
 /**
  * @return void
  */
 public function fire()
 {
     $database = $this->getDatabase($this->input->getOption('database'));
     $this->checkDumpFolder();
     //----------------
     $dbfile = new BackupFile($this->argument('filename'), $database, $this->getDumpsPath());
     $this->filePath = $dbfile->path();
     $this->fileName = $dbfile->name();
     $status = $database->dump($this->filePath);
     $handler = new BackupHandler($this->colors);
     // Error
     //----------------
     if ($status !== true) {
         return $this->line($handler->errorResponse($status));
     }
     // Compression
     //----------------
     if ($this->isCompressionEnabled()) {
         $this->compress();
         $this->fileName .= ".gz";
         $this->filePath .= ".gz";
     }
     $this->line($handler->dumpResponse($this->argument('filename'), $this->filePath, $this->fileName));
     // S3 Upload
     //----------------
     if ($this->option('upload-s3')) {
         $this->uploadS3();
         $this->line($handler->s3DumpResponse());
         if ($this->option('keep-only-s3')) {
             File::delete($this->filePath);
             $this->line($handler->localDumpRemovedResponse());
         }
     }
 }
Example #8
0
 /**
  * @param \Onyx\Destiny\Objects\Hash $hash
  * @param string $index
  * @return bool
  */
 public static function saveImageLocally($hash, $index = 'extra')
 {
     // BUG: Can't use variable object indexes implicitly
     // $hash->{$index} should work but doesn't
     // map the index explicitly with the attributes dumped into $bug
     $bug = $hash->getAttributes();
     $url = "https://bungie.net" . $bug[$index];
     $name = $index != 'extra' ? '_bg' : null;
     $name = $hash->hash . $name;
     // Make sure we aren't trying to save something that isn't an image
     // We only need this check because we cheat and store all hash related objects
     // in one table. This means we have crazy cheats to get things done.
     if (strlen($bug[$index]) < 5) {
         return false;
     }
     $location = public_path('uploads/thumbs/');
     $filename = $name . "." . pathinfo($bug[$index], PATHINFO_EXTENSION);
     if (File::isFile($location . $filename)) {
         return true;
     }
     if ($hash instanceof Hash) {
         $manager = new ImageManager();
         try {
             $img = $manager->make($url);
             $img->save($location . $filename);
         } catch (NotReadableException $e) {
             Log::error('Could not download: ' . $url);
         }
         return true;
     }
 }
 public function savePost()
 {
     $post = ['title' => Input::get('title'), 'content' => Input::get('content'), 'picture' => Input::get('picture')];
     $rules = ['title' => 'required', 'content' => 'required'];
     $valid = Validator::make($post, $rules);
     if ($valid->passes()) {
         $post = new Post($post);
         $post->comment_count = 0;
         $post->read_more = strlen($post->content) > 120 ? substr($post->content, 0, 120) : $post->content;
         /*
         $destinationPath = 'uploads'; // upload path
         			//$extension = Input::file('image')->getClientOriginalExtension(); // getting image extension
         			$fileName = time(); // renameing image
         			Input::file('images')->make($destinationPath, $fileName); // uploading file to given path
         			$post->images = Input::get($fileName);
         
         
         			$pic = Input::file('picture');
                
                     $pic_name = time();
                     Image::make($pic)->save(public_path().'/images/300x'.$pic_name);
                     $post->images = '/images/'.'300x'.$pic_name;
         			$post->images = Input::get($pic_name);
         */
         $file = Request::file('picture');
         $extension = $file;
         Images::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file));
         $post->images = $file->time();
         $post->save();
         return Redirect::to('admin/dash-board')->with('success', 'Post is saved!');
     } else {
         return Redirect::back()->withErrors($valid)->withInput();
     }
 }
Example #10
0
 public function run()
 {
     // get files in database/seeds folder
     $path = base_path('database/seeds');
     $files = array_map(function ($filename) {
         return str_replace(".php", "", $filename);
     }, array_map('basename', File::files($path)));
     // get entries in database
     $seeded = DB::table('seeded')->lists('seeder');
     // find seeds that need to be done
     foreach ($files as $file) {
         if ($file == 'DatabaseSeeder') {
             continue;
         }
         if (in_array($file, $seeded)) {
             continue;
         }
         // call the seeder
         Model::unguard();
         $this->command->info("Calling {$file}");
         try {
             $this->call($file);
             DB::table('seeded')->insert(['seeder' => $file]);
         } catch (Exception $e) {
             $this->command->error("Error in {$file}");
         }
         Model::reguard();
     }
 }
Example #11
0
 public function fire()
 {
     $stubs = __DIR__ . '/stubs/lang.stub';
     $name = strtolower($this->argument('name'));
     $path = base_path('resources/lang/tr/admin/' . $name . '.php');
     File::copy($stubs, $path);
 }
 /**
  * Create a directory to store some working files.
  *
  * @return string
  */
 public function createTempDirectory()
 {
     $tempDirectory = storage_path('medialibrary/temp/' . str_random(16));
     File::makeDirectory($tempDirectory, 493, true);
     Gitignore::createIn(storage_path('medialibrary'));
     return $tempDirectory;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     if (File::exists(Config::publishedSeederRealpath())) {
         if (!$this->confirm('The seeder file already exists, overwrite it? [Yes|no]')) {
             $this->line('');
             return $this->info('Okay, no changes made to the file.');
         }
     }
     // Laravel 5.0 does not have make:seed command
     // in that case ignore the command and copy the contents
     // of the file directly.
     try {
         $this->callSilent('make:seed', ['name' => Config::seederNameKey()]);
     } catch (\Exception $ex) {
     }
     $inputFile = file_get_contents(Config::localSeederPath());
     $outputFile = fopen(Config::publishedSeederRealpath(), 'w');
     if ($inputFile && $outputFile) {
         fwrite($outputFile, $inputFile);
         fclose($outputFile);
     } else {
         File::delete(Config::publishedSeederRealpath());
         $this->line('');
         return $this->error('There was an error creating the seeder file, ' . 'check write permissions for database/seeds directory' . PHP_EOL . PHP_EOL . 'If you think this is a bug, please submit a bug report ' . 'at https://github.com/moharrum/laravel-geoip-world-cities/issues');
     }
     $this->line('');
     $this->info('Okay, seeder file created successfully.');
 }
 public function uploadW9(Request $request, $link, $app_name, $aff_code)
 {
     $affiliate_row = Affiliate::where('external_link', '=', $link)->first();
     if ($affiliate_row == null) {
         return redirect('error');
     }
     //$user_infusionsoft = UserInfusionsoft::where('app_name','=', $app_name)->first();
     $user_infusionsoft = $affiliate_row->infusionsoft_user;
     $app_infusionsoft = new iSDK();
     if (!$app_infusionsoft->cfgCon($user_infusionsoft->app_name, $user_infusionsoft->app_apikey)) {
         return redirect('error');
     }
     $file = $request->file('w9file');
     if ($file) {
         $extension = $file->getClientOriginalExtension();
         $mimeType = $file->getMimeType();
         if (strtolower($extension) != 'pdf' || $mimeType != 'application/pdf') {
             return redirect(URL::to('aff/' . $link . '/' . $app_name . '/' . $aff_code))->with('error', 'You can upload pdf files only.');
         }
         Storage::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file));
         $affiliate_row->w9_file_original_name = $file->getClientOriginalName();
         $affiliate_row->w9_file = $file->getFilename() . '.' . $extension;
         $affiliate_row->save();
         return redirect(URL::to('aff/' . $link . '/' . $app_name . '/' . $aff_code))->with('success', 'Congratulations! Your W9 is uploaded.');
     }
     return redirect(URL::to('aff/' . $link . '/' . $app_name . '/' . $aff_code))->with('error', 'No file is selected.');
 }
Example #15
0
 public function add()
 {
     $file = Request::file('file');
     if (Request::hasFile('file')) {
         $extension = $file->getClientOriginalExtension();
         Storage::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file));
         $entry = new \App\File();
         $entry->mime = $file->getClientMimeType();
         $entry->original_filename = $file->getClientOriginalName();
         $entry->filename = $file->getFilename() . '.' . $extension;
         $entry->save();
         $part = new Part();
         $part->file_id = $entry->id;
         $part->name = Request::input('name');
         $part->sku = Request::input('sku');
         $part->make = Request::input('make');
         $part->year = Request::input('year');
         $part->condition = Request::input('condition');
         $part->description = Request::input('description');
         $part->price = Request::input('price');
         $part->imageurl = Request::input('imageurl');
         if (Request::has('price')) {
             $part->save();
         }
     }
     return redirect('/admin/part');
 }
Example #16
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store($image, $type, $primary_id, $current_link)
 {
     $image_link = array_key_exists($type, Input::all()) ? Input::file($type) != '' ? '/allgifted-images/' . $type . '/' . $primary_id . '.' . $image->getClientOriginalExtension() : $current_link : $current_link;
     array_key_exists($type, Input::all()) ? File::exists(public_path($image_link)) ? File::delete(public_path($image_link)) : null : null;
     $image ? Image::make($image)->fit(500, 300)->save(public_path($image_link)) : null;
     return $image_link;
 }
 public static function boot()
 {
     parent::boot();
     CourseGalleryItem::deleting(function ($courseGalleryItem) {
         File::delete($courseGalleryItem->image);
     });
 }
 protected function createFile($fileName, $routeFile, $stubFile)
 {
     $stubFile = str_replace('{$NAME$}', $fileName, $stubFile);
     if (File::put($routeFile, $stubFile)) {
         $this->info('Route generated!');
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['file' => 'mimes:pdf', 'year' => 'required']);
     if ($validator->fails()) {
         return redirect()->back()->withErrors(['file' => 'ไฟล์จะต้องเป็น .pdf เท่านั้น'])->withInput();
     }
     //example of delete exist file
     $existMeetingReport = MeetingReport::where('year', '=', $request->get('year'))->where('no', '=', $request->get('no'))->first();
     if ($existMeetingReport != null) {
         $filename = base_path() . '/public/uploads/Meeting-reports/' . $request->get('year') . '/' . $existMeetingReport->file_path;
         if (File::exists($filename)) {
             File::delete($filename);
         }
         MeetingReport::destroy($existMeetingReport->id);
     }
     if (Input::file('file')->isValid()) {
         $filePath = $request->get('no') . '.pdf';
         if (Input::file('file')->move(base_path() . '/public/uploads/Meeting-reports/' . $request->get('year'), $filePath)) {
             $meetingReport = new MeetingReport();
             $meetingReport->file_path = $filePath;
             $meetingReport->year = $request->get('year');
             $meetingReport->no = $request->get('no');
             $meetingReport->save();
             return redirect('/admin/management');
         } else {
             return redirect()->back()->withErrors(['error_message' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']);
         }
     }
 }
Example #20
0
 public function rmFile($filename)
 {
     $fileUploadDir = 'files/uploads/';
     if (File::exists($fileUploadDir . $filename)) {
         File::delete($fileUploadDir . $filename);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['file' => 'mimes:pdf', 'name' => 'max:100']);
     if ($validator->fails()) {
         return redirect()->back()->withErrors(['file' => 'ไฟล์จะต้องเป็น .pdf เท่านั้น'])->withInput();
     }
     if (Input::file('file')->isValid()) {
         $filePath = date('Ymd_His') . '.pdf';
         if (Input::file('file')->move(base_path() . '/public/uploads/Announces/Announce-' . $request->get('year'), $filePath)) {
             //example of delete exist file
             $announceList = Announce::all();
             if (sizeof($announceList) != 0) {
                 $lastAnnounce = $announceList[sizeof($announceList) - 1];
                 $filename = base_path() . '/public/uploads/Announces/Announce-/' . $request->get('year') . '/' . $lastAnnounce->file_path;
                 if (File::exists($filename)) {
                     File::delete($filename);
                 }
                 //                    $oldAnnounce = Announce::findOrNew($lastAnnounce->id);
                 $lastAnnounce = DB::table('announces')->where('year', $request->get('year'))->first();
                 //                    dd($lastAnnounce);die;
                 if ($lastAnnounce != null) {
                     Announce::destroy($lastAnnounce->id);
                 }
             }
             $announce = new Announce();
             $announce->file_path = $filePath;
             $announce->year = $request->get('year');
             $announce->save();
             return redirect('/announces');
         } else {
             return redirect()->back()->withErrors(['error_message' => 'ไฟล์อัพโหลดมีปัญหากรุณาลองใหม่อีกครั้ง']);
         }
     }
 }
 public function updateFile($id, Request $request)
 {
     $file = $request->file('updateFile');
     $entry = FileRecord::where('id', '=', $id)->firstOrFail();
     Storage::disk('local')->put($entry->owner_id . $entry->id . $entry->filename . "/" . ($entry->total_versions + 1), File::get($file));
     $entry->total_versions = $entry->total_versions + 1;
     $entry->public_version = $entry->total_versions;
     $docVersions = (array) json_decode($entry->version_details);
     $version = $entry->total_versions - 1;
     $note = $request->updateDetails;
     $date = Carbon::now();
     $user = Auth::User()->fname . ' ' . Auth::User()->lname;
     $versionArray = [$version => array('user' => $user, 'stamp' => $date, 'note' => $note)];
     $finalVer = json_encode(array_merge($docVersions, $versionArray));
     $entry->version_details = $finalVer;
     $entry->save();
     $admins = User::get()->where('user_type_id', 1);
     foreach ($admins as $admin) {
         $uploader = Auth::user()->fname . " " . Auth::user()->lname . " (" . Auth::user()->username . ")";
         Mail::queue('mail.adminFileUpdate', ['uploader' => $uploader, 'fileName' => $entry->filename, 'id' => $entry->id, 'version' => $entry->public_version], function ($message) use(&$admin) {
             $message->to($admin->email, $admin->fname)->subject('New File Update');
         });
     }
     return redirect('/');
 }
 public function add(Request $request)
 {
     $name = Input::get('user_name');
     $id = Input::get('user_id');
     $text = Input::get('description');
     if ($request->hasFile('filefield')) {
         $file = $request->file('filefield');
         $entry = new Fileentry();
         $filename = time() . '.' . $file->getClientOriginalExtension();
         $extension = $file->getClientOriginalExtension();
         //			Image::make($file)->orientate()->save(public_path('recipe/'. $filename));
         Storage::disk('local')->put($file->getFileName() . '.' . $extension, File::get($file));
         $entry->mime = $file->getClientMimeType();
         $entry->original_filename = $file->getClientOriginalName();
         $entry->filename = $file->getFilename() . '.' . $extension;
     }
     $entry->user_name = $name;
     $entry->user_id = $id;
     $entry->description = $text;
     $entry->save();
     //		$file = Request::file('filefield');
     //		$extension = $file->getClientOriginalExtension();
     //		Storage::disk('local')->put($file->getFilename().'.'.$extension,  File::get($file));
     //		$entry = new Fileentry();
     //		$entry->mime = $file->getClientMimeType();
     //		$entry->original_filename = $file->getClientOriginalName();
     //		$entry->filename = $file->getFilename().'.'.$extension;
     //		$entry->user_name = $name;
     //		$entry->user_id = $id;
     //		$entry->description = $text;
     //
     //		$entry->save();
     return redirect('/');
 }
 public function add(Request $request)
 {
     $this->validate($request, ['empleado' => 'required', 'filefield' => 'required']);
     $file = $request->file('filefield');
     $extension = $file->getClientOriginalExtension();
     if ($extension !== 'pdf') {
         return redirect()->back()->with('info', 'El archivo debe ser un pdf válido');
     }
     $user_id = $request->empleado;
     $user = User::where('id', $user_id)->first();
     $nombre = $user->username;
     $mes = $request->month;
     // Esto no funciona y no se porque
     // setlocale(LC_TIME,"es_ES.UTF-8");
     // $monthName = strftime('%B', mktime(0, 0, 0, $mes));
     // $monthName = strftime("m", mktime(0, 0, 0, $mes, 10));
     $year = $request->year;
     $descripcion = $mes . ' ' . $year . ' ' . strtoupper($nombre);
     Storage::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file));
     $entry = new Fileentry();
     $entry->mime = $file->getClientMimeType();
     $entry->original_filename = $file->getClientOriginalName();
     $entry->filename = $file->getFilename() . '.' . $extension;
     $entry->mes = $mes;
     $entry->year = $year;
     $entry->user_id = $user_id;
     $entry->descripcion = $descripcion;
     $entry->save();
     return redirect('fileentry')->withInput();
 }
 public function saveThumbnailImage(Request $request)
 {
     $file = $request->file('product_thumbnail_img');
     if ($file && $_FILES["product_thumbnail_img"]["tmp_name"]) {
         try {
             $preview_img_x = $_POST['x_thumbnail'];
             $preview_img_y = $_POST['y_thumbnail'];
             $preview_img_w = $_POST['w_thumbnail'];
             $preview_img_h = $_POST['h_thumbnail'];
             $display_w = $_POST['display_w_thumbnail'];
             $file_path = $file->getPathname();
             $orig_w = getimagesize($_FILES["product_thumbnail_img"]["tmp_name"])[0];
             $ratio = $orig_w / $display_w;
             $fileUploadDir = 'files/uploads/';
             $fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension();
             if (File::exists($fileUploadDir . $fileName)) {
                 $fileName = $file->getFilename() . time() . "." . $file->getClientOriginalExtension();
             }
             $img = \Img::make($file_path)->crop((int) ($preview_img_w * $ratio), (int) ($preview_img_h * $ratio), (int) ($preview_img_x * $ratio), (int) ($preview_img_y * $ratio));
             $img->resize(300, 167);
             $img->save($fileUploadDir . $fileName);
             return $fileName;
         } catch (Exception $e) {
             return false;
         }
     }
     return false;
 }
 public function putEdit(Request $request)
 {
     if (!ACL::hasPermission('awards', 'edit')) {
         return redirect(route('awards'))->withErrors(['Você não pode editar os prêmios.']);
     }
     $this->validate($request, ['title' => 'required|max:45', 'warning' => 'required', 'image' => 'image|mimes:jpeg,bmp,gif,png'], ['title.required' => 'Informe o título do prêmio', 'title.max' => 'O título do prêmio não pode passar de :max caracteres', 'warning.required' => 'Informe o aviso sobre o prêmio', 'image.image' => 'Envie um formato de imagem válida', 'image.mimes' => 'Formato suportado: .png com fundo transparente']);
     $award = Awards::find($request->awardsId);
     $award->title = $request->title;
     $award->warning = $request->warning;
     if ($request->image) {
         //DELETE OLD IMAGE
         if ($request->currentImage != "") {
             if (File::exists($this->folder . $request->currentImage)) {
                 File::delete($this->folder . $request->currentImage);
             }
         }
         $extension = $request->image->getClientOriginalExtension();
         $nameImage = Carbon::now()->format('YmdHis') . "." . $extension;
         Image::make($request->file('image'))->resize($this->imageWidth, $this->imageHeight)->save($this->folder . $nameImage);
         $award->image = $nameImage;
     }
     $award->save();
     $success = "Prêmio editado com sucesso";
     return redirect(route('awards'))->with(compact('success'));
 }
Example #27
0
 public function actualizar($id, Request $request)
 {
     try {
         $rules = array('nombre' => array('required', 'string', 'min:5', 'unique:promociones,nombre' . $id), 'descripcion' => array('required', 'string', 'min:30'), 'imagen' => array('image', 'image_size:>=300,>=300'), 'inicio' => array('date'), 'fin' => array('date', 'after: inicio'));
         $this->validate($request, $rules);
         $registro = Promociones::find($id);
         $registro->nombre = \Input::get('nombre');
         $registro->descripcion = \Input::get('descripcion');
         if ($archivo = BRequest::file('foto')) {
             $foto = BRequest::file('imagen');
             $extension = $foto->getClientOriginalExtension();
             Storage::disk('image')->put($foto->getFilename() . '.' . $extension, File::get($foto));
             $registro->imagen = $foto->getFilename() . '.' . $extension;
         }
         if ($inicio = \Input::get('inicio')) {
             $registro->inicio = \Input::get('inicio');
         }
         if ($inicio = \Input::get('fin')) {
             $registro->fin = \Input::get('fin');
         }
         $registro->save();
         return \Redirect::route('adminPromociones')->with('alerta', 'La promocion ha sido modificada con exito!');
     } catch (ValidationException $e) {
         return \Redirect::action('PromocionesCtrl@editar', array('id' => $id))->withInput()->withErrors($e->get_errors());
     }
 }
Example #28
0
 public function saveImage($path, $filename, $file)
 {
     $image = File::get($file);
     $fullpath = $path . $filename;
     Storage::disk('local')->put($fullpath, $image);
     return $fullpath;
 }
Example #29
0
 public function download($id)
 {
     $file = File::findOrFail($id);
     $pathToFile = 'get_link_to_download/' . md5($file->name . time());
     FileHelpers::copy(storage_path('app') . '/' . $file->local_name, $pathToFile);
     return response()->download($pathToFile, $file->name, ['Content-Type'])->deleteFileAfterSend(true);
 }
Example #30
0
 public static function boot()
 {
     parent::boot();
     ProductCategory::deleting(function ($productTag) {
         File::delete($productTag->image);
     });
 }