file() public static method

Retrieve a file from the request.
public static file ( string $key = null, mixed $default = null ) : Illuminate\Http\UploadedFile | array | null
$key string
$default mixed
return Illuminate\Http\UploadedFile | array | null
コード例 #1
1
 public function record()
 {
     if (\Request::hasFile('image') && \Request::file('image')->isValid() && \Auth::user()->suspend == false) {
         $file = \Request::file('image');
         $input = \Request::all();
         $date = new \DateTime();
         if (isset($input['anon'])) {
             $name = 'anon';
         } else {
             $name = \Auth::user()->name;
         }
         $validator = \Validator::make(array('image' => $file, 'category' => $input['category'], 'title' => $input['title'], 'caption' => $input['caption']), array('image' => 'required|max:1200|mimes:jpeg,jpg,gif', 'category' => 'required', 'title' => 'required|max:120', 'caption' => 'required|max:360'));
         if ($validator->fails()) {
             return redirect('/publish')->withErrors($validator);
         } else {
             $unique = str_random(10);
             $fileName = $unique;
             $destinationPath = 'database/pictures/stream_' . $input['category'] . '/';
             \Request::file('image')->move($destinationPath, $fileName);
             \DB::insert('insert into public.moderation (p_cat, p_ouser, p_title, p_caption, p_imgurl, p_status, p_reported, p_rating, created_at, updated_at) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [$input['category'], $name, $input['title'], $input['caption'], $unique, 'available', 0, 0, $date, $date]);
             $messages = 'Your content has been succesfully submitted. Going on moderation process.';
             return redirect('/system/notification')->with('messages', $messages);
         }
     } else {
         $messages = 'Your content data is invalid. The process is aborted.';
         return redirect('/system/notification')->with('messages', $messages);
     }
 }
コード例 #2
0
ファイル: Controller.php プロジェクト: safaricco/admfw
 public static function upload(Request $request, $tipo, $registroTabela)
 {
     // A VARIÁVEL $nomeTipo CONTÉM O NOME DO TIPO DA MIDIA E SERÁ USADA COMO NOME DA PASTA DENTRO DA PASTA UPLOADS
     $nomeTipo = TipoMidia::findOrFail($tipo)->descricao;
     // CRIANDO O REGISTRO PAI NA TABELA MIDIA
     $midia = new Midia();
     $midia->id_tipo_midia = $tipo;
     $midia->id_registro_tabela = $registroTabela;
     $midia->descricao = $nomeTipo . ' criado automaticamente com o banner';
     $midia->save();
     // FAZENDO O UPLOAD E GRAVANDO NA TABELA MULTIMIDIA
     #foreach ($request-> as $img) :
     // VERIFICANDO SE O ARQUIVO NÃO ESTÁ CORROMPIDO
     if ($request->hasFile('imagens')) {
         // PEGANDO O NOME ORIGINAL DO ARQUIVO A SER UPADO
         $nomeOriginal = $request->file('imagem')->getClientOriginalName();
         // MONTANDO O NOVO NOME COM MD5 + IDUNICO BASEADO NO NOME ORIGINAL E CONCATENANDO COM A EXTENÇÃO DO ARQUIVO
         $novoNome = md5(uniqid($nomeOriginal)) . '.' . $request->file('imagem')->getClientOriginalExtension();
         // MOVENDO O ARQUIVO PARA A PASTA UPLOADS/"TIPO DA MIDIA"
         $request->file('imagem')->move('uploads/' . $nomeTipo, $novoNome);
         // GRAVANDO NA TABELA MULTIMIDIA
         $imagem = new Multimidia();
         // PREPARANDO DADOS PARA GRAVAR NA TABELA MULTIMIDIA
         $imagem->id_midia = $midia->id_midia;
         $imagem->imagem = $novoNome or '';
         $imagem->descricao = $request->descricao or '';
         $imagem->link = $request->link or '';
         $imagem->ordem = $request->ordem or '';
         $imagem->video = $request->video or '';
         $imagem->save();
     }
     #endforeach;
 }
コード例 #3
0
 /**
  * Upload the file and store
  * the file path in the DB.
  */
 public function store()
 {
     // Rules
     $rules = array('name' => 'required', 'file' => 'required|max:20000');
     $messages = array('max' => 'Please make sure the file size is not larger then 20MB');
     // Create validation
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $directory = "uploads/files/";
     // Before anything let's make sure a file was uploaded
     if (Input::hasFile('file') && Request::file('file')->isValid()) {
         $current_file = Input::file('file');
         $filename = Auth::id() . '_' . $current_file->getClientOriginalName();
         $current_file->move($directory, $filename);
         $file = new Upload();
         $file->user_id = Auth::id();
         $file->project_id = Input::get('project_id');
         $file->name = Input::get('name');
         $file->path = $directory . $filename;
         $file->save();
         return Redirect::back();
     }
     $upload = new Upload();
     $upload->user_id = Auth::id();
     $upload->project_id = Input::get('project_id');
     $upload->name = Input::get('name');
     $upload->path = $directory . $filename;
     $upload->save();
     return Redirect::back();
 }
コード例 #4
0
 public function convertir()
 {
     $fileName = \Request::file('file');
     $importador = new ImportadorProyecto($fileName);
     $importador->convertir();
     return redirect()->action('ImportarProyectoController@show');
 }
コード例 #5
0
 public function upload(Request $request)
 {
     $file = array('photo' => $request->file('photo'));
     $rules = array('photo' => 'required');
     $validator = \Validator::make($file, $rules);
     if ($validator->fails()) {
         return \Response::json(array('success' => false));
     } else {
         // checking file is valid.
         if (\Request::file('photo')->isValid()) {
             $destinationPath = 'resources/images/userpics';
             // upload path
             $extension = \Request::file('photo')->getClientOriginalExtension();
             // getting image extension
             $fileName = rand(11111, 99999) . '.' . $extension;
             // renameing image
             \Request::file('photo')->move($destinationPath, $fileName);
             //updateing Contact record in database //Decided not to do this here. Will send back the filename
             //and update the record on client side and then send back to save. This way the picture gets updated
             //on form without having to reoad the whole store.
             // $contact = Contact::find($request->get('contact_id'));
             // $contact->picturefile = $fileName;
             // $contact->save();
             return \Response::json(array('success' => true, 'filename' => $fileName));
         } else {
             return \Response::json(array('success' => false));
         }
     }
 }
コード例 #6
0
 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();
     }
 }
コード例 #7
0
 public function editRecord()
 {
     $name = \Auth::user()->name;
     if (\Request::hasFile('avatar') && \Request::file('avatar')->isValid()) {
         $file = \Request::file('avatar');
         $input = \Request::all();
         $validator = \Validator::make(array('avatar' => $file, 'bio' => $input['bio']), array('avatar' => 'max:800|mimes:jpeg,jpg,gif', 'bio' => 'max:1000'));
         if ($validator->fails()) {
             return redirect('/profile/edit')->withErrors($validator);
         } else {
             if ($input['avatar_path'] == '0') {
                 $unique = str_random(20);
                 $fileName = $unique;
             } else {
                 $fileName = $input['avatar_path'];
             }
             $destinationPath = 'database/pictures/avatars/';
             \Request::file('avatar')->move($destinationPath, $fileName);
             \DB::table('users_data')->where('name', $name)->update(['bio' => $input['bio'], 'avatar' => $fileName]);
             return redirect('/profile/' . $name);
         }
     } else {
         $input = \Request::all();
         $validator = \Validator::make(array('bio' => $input['bio']), array('bio' => 'max:1000'));
         if ($validator->fails()) {
             return redirect('/profile/edit')->withErrors($validator);
         } else {
             \DB::table('users_data')->where('name', $name)->update(['bio' => $input['bio']]);
             return redirect('/profile/' . $name);
         }
     }
 }
コード例 #8
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());
     }
 }
コード例 #9
0
ファイル: Image.php プロジェクト: pseudoagentur/soa-sentinel
 public static function registerRoutes()
 {
     Route::post('upload/' . static::$route, ['as' => 'admin.upload.' . static::$route, function () {
         $validator = Validator::make(\Request::all(), static::uploadValidationRules());
         if ($validator->fails()) {
             return Response::make($validator->errors()->get('file'), 400);
         }
         $file = \Request::file('file');
         $upload_path = config('admin.filemanagerDirectory') . \Request::input('path');
         $orginalFilename = str_slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));
         $filename = $orginalFilename . '.' . $file->getClientOriginalExtension();
         $fullpath = public_path($upload_path);
         if (!\File::isDirectory($fullpath)) {
             \File::makeDirectory($fullpath, 0755, true);
         }
         if ($oldFilename = \Request::input('filename')) {
             \File::delete($oldFilename);
         }
         if (\File::exists($fullpath . '/' . $filename)) {
             $filename = str_slug($orginalFilename . '-' . time()) . '.' . $file->getClientOriginalExtension();
         }
         $filepath = $upload_path . '/' . $filename;
         $file->move($fullpath, $filename);
         return ['url' => asset($filepath), 'value' => $filepath];
     }]);
     Route::post('upload/delete/' . static::$route, ['as' => 'admin.upload.delete.' . static::$route, function () {
         if ($filename = \Request::input('filename')) {
             \File::delete($filename);
             return "Success";
         }
         return null;
     }]);
 }
コード例 #10
0
ファイル: DeliverableController.php プロジェクト: smhillin/p4
 public function addDeliverable(Request $request)
 {
     $messages = ['not_in' => "You have to choose a client.", 'url' => "Your url must be in the form http://domain.com"];
     $this->validate($request, ['deliverable_name' => 'required|max:25', 'client_id' => 'not_in:0', 'deliverable_url' => 'url'], $messages);
     $deliverable = new \p4\Deliverable();
     $user = \Auth::user();
     $client = \p4\Client::find($request->client_id);
     $file = \Request::file('deliverable_file');
     if ($file) {
         $extension = $file->getClientOriginalExtension();
         $filename = $file->getClientOriginalName();
         $file->move(public_path() . '/uploads/', $filename);
         $location = '/uploads/' . $filename;
         $deliverable->attachment = $location;
     }
     $deliverable->url = \Request::get('deliverable_url');
     $deliverable->name = \Request::get('deliverable_name');
     $deliverable->created_by = $user->id;
     $deliverable->date_delivered = Date('Y-m-d H:i:s');
     $deliverable->client_id = \Request::get('client_id');
     $deliverable->status = \Request::get('status');
     $deliverable->client()->associate($client);
     $deliverable->save();
     $data = array('client' => $client, 'deliverable' => $deliverable);
     /**sends email confirmation to client after deliverable is added**/
     \Mail::send('emails.deliverable-available', $data, function ($message) use($client, $deliverable) {
         $recepient_email = $client->email;
         $recepient_name = $client->name;
         $subject = 'Your deliverable is now ready for you to review';
         $message->to($recepient_email, $recepient_name)->subject($subject);
     });
     \Session::flash('message', 'Your Deliverable Has Been Uploaded');
     return redirect()->back();
 }
コード例 #11
0
ファイル: ProfileService.php プロジェクト: lyovkin/v2board
 /**
  * Upload profile image
  */
 public function uploadImage($request, $model)
 {
     if (\Request::file('upl')) {
         $image = ImageUploadFacade::attachmentUpload($request->file('upl'), new ProfileAttachment(), 'profile');
         $this->updateProfile(['attachment_id' => $image->id], $model);
         return $image;
     }
 }
コード例 #12
0
ファイル: helpers.php プロジェクト: Jokeramc/amc
function uploadOneImage(Request $request, $imageName, $thumb = [])
{
    $uploadPath = config('shop.UPLOAD_ROOT_PATH');
    $ext = config('shop.UPLOAD_ALLOW_EXT');
    //取出php.ini里面允许上传单个文件的大小配置
    $upload_max_filesize = (int) ini_get('upload_max_filesize');
    //取出配置的上传文件的大小与php.ini中的比较取最小值
    $upload_file_size = (int) config('shop.UPLOAD_FILE_SIZE');
    $upload_max_size = min($upload_max_filesize, $upload_file_size);
    $result = array();
    //文件类型
    $mime = $request->file($imageName)->getClientMimeType();
    if (!in_array($mime, $ext)) {
        $result['status'] = 0;
        $result['info'] = '文件类型错误,只能上传图片';
        return $result;
    }
    //文件大小
    $max_size = $upload_max_size * 1024 * 1024;
    $size = $request->file($imageName)->getClientSize();
    if ($size > $max_size) {
        $result['status'] = 0;
        $result['info'] = '文件大小不能超过' . $max_size;
        return $result;
    }
    //上传文件夹,如果不存在,建立文件夹
    $date = date("Y_m_d");
    $path = $uploadPath . $date;
    if (!is_dir($path)) {
        mkdir($path, 0777, true);
    }
    //生成新文件名
    //取得之前文件的扩展名
    $extension = $request->file($imageName)->getClientOriginalExtension();
    $file_name = date("Ymd_His") . '_' . rand(10000, 99999) . '.' . $extension;
    $request->file($imageName)->move($path, $file_name);
    $img = [];
    //原图路径
    $img[0] = $uploadPath . $date . '/' . $file_name;
    //生成缩略图
    if ($thumb) {
        foreach ($thumb as $k => $v) {
            //打开原图
            $goods_ori = Image::make($path . '/' . $img[0]);
            //定义生成缩略图的保存路径(名字)
            $thumbname = $uploadPath . $date . '/' . $k . '_thumb_' . $file_name;
            $goods_ori->resize($v[0], $v[1])->save($thumbname);
            //将缩略图的路径放入img数组中用于返回
            $img[] = $thumbname;
        }
    }
    //返回新文件名
    $result['status'] = 1;
    $result['info'] = $img;
    return $result;
}
コード例 #13
0
ファイル: Request.php プロジェクト: hofmeister/Pimple
 /**
  * Get F parms
  *
  * @param string $key
  * @param mixed $default
  * @return Request_Parms
  */
 public static function file($key = null, $default = null)
 {
     if ($key) {
         return self::file()->{$key} ? self::file()->{$key} : $default;
     }
     if (!self::$file) {
         self::$file = new Request_Multipart($_FILES);
     }
     return self::$file;
 }
コード例 #14
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $s3 = AWS::get('s3');
     $s3Bucket = 'buildbrighton-bbms';
     if (Request::hasFile('image')) {
         $file = Request::file('image');
         $event = Request::get('textevent');
         $time = Request::get('time');
         $fileData = Image::make($file)->encode('jpg', 80);
         $date = Carbon::createFromFormat('YmdHis', $event);
         $folderName = $date->hour . ':' . $date->minute . ':' . $date->second;
         try {
             $newFilename = \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName . '/' . $time . '.jpg';
             $s3->putObject(array('Bucket' => $s3Bucket, 'Key' => $newFilename, 'Body' => $fileData, 'ACL' => 'public-read', 'ContentType' => 'image/jpg', 'ServerSideEncryption' => 'AES256'));
         } catch (\Exception $e) {
             \Log::exception($e);
         }
         //Log::debug('Image saved :https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/'.$newFilename);
     }
     if (Request::get('eventend') == 'true') {
         $event = Request::get('textevent');
         $date = Carbon::createFromFormat('YmdHis', $event);
         $folderName = $date->hour . ':' . $date->minute . ':' . $date->second;
         $iterator = $s3->getIterator('ListObjects', array('Bucket' => $s3Bucket, 'Prefix' => \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName));
         $images = [];
         $imageDurations = [];
         foreach ($iterator as $object) {
             $images[] = 'https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/' . $object['Key'];
             $imageDurations[] = 35;
         }
         if (count($images) <= 2) {
             //only two images, probably two bad frames
             //delete them
             foreach ($iterator as $object) {
                 Log::debug("Deleting small event image " . $object['Key']);
                 $s3->deleteObject(['Bucket' => $s3Bucket, 'Key' => $object['Key']]);
             }
             return;
         }
         $gc = new GifCreator();
         $gc->create($images, $imageDurations, 0);
         $gifBinary = $gc->getGif();
         //Delete the individual frames now we have the gif
         foreach ($iterator as $object) {
             //Log::debug("Processed gif, deleting frame, ".$object['Key']);
             $s3->deleteObject(['Bucket' => $s3Bucket, 'Key' => $object['Key']]);
         }
         //Save the gif
         $newFilename = \App::environment() . '/cctv/' . $date->year . '/' . $date->month . '/' . $date->day . '/' . $folderName . '.gif';
         $s3->putObject(array('Bucket' => $s3Bucket, 'Key' => $newFilename, 'Body' => $gifBinary, 'ACL' => 'public-read', 'ContentType' => 'image/gif', 'ServerSideEncryption' => 'AES256'));
         //Log::debug('Event Gif generated :https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/'.$newFilename);
         \Slack::to("#cctv")->attach(['image_url' => 'https://s3-eu-west-1.amazonaws.com/buildbrighton-bbms/' . $newFilename, 'color' => 'warning'])->send('Movement detected');
     }
 }
コード例 #15
0
 public function store(Song $songs)
 {
     $songs->title = \Request::get('title');
     $songs->lyrics = \Request::get('lyrics');
     $songs->slug = \Request::get('slug');
     $songs->save();
     $file = \Request::file('myname');
     $imageName = $songs->slug . '.' . $file->getClientOriginalExtension();
     \Request::file('myname')->move(base_path() . '/public/images/catalog/', $imageName);
     return Redirect('songs');
 }
コード例 #16
0
 /**
  * Move Uploaded file to the specified location
  * @param string $input 
  * @param string $name 
  * @param string $location 
  * @return ImageFile instance
  */
 protected function moveUploadedFile($input, $name, $location)
 {
     $uploaded = \Request::file($input);
     // Save the original Image File
     $image_file = new ImageFile();
     $image_file->originalname = $uploaded->getClientOriginalName();
     $image_file->filename = $this->generateFilename($name);
     $image_file->extension = $uploaded->getClientOriginalExtension();
     $image_file->mime = $uploaded->getMimeType();
     $image_file->fullpath = $location . '/' . $image_file->getBaseName();
     $uploaded->move($location, $image_file->getBaseName());
     return $image_file;
 }
コード例 #17
0
ファイル: request.php プロジェクト: uwitec/mgoa
 public static function init()
 {
     if (ini_get('magic_quotes_gpc')) {
         self::$get = $_GET;
         self::$post = $_POST;
     } else {
         self::$get = $_GET = self::addSlashes($_GET);
         self::$post = $_POST = self::addSlashes($_POST);
     }
     self::$cookie = $_COOKIE;
     self::$file = $_FILES;
     self::$method = $_SERVER['REQUEST_METHOD'];
 }
コード例 #18
0
 public static function uploadPhotos($oImage, $sfile)
 {
     $sDestination = 'images/photos/';
     //$sName =$oImage->getClientOriginalName();
     // dd($sDestination);
     $sDate = date('YmdHis');
     if (Request::file($sfile)->move($sDestination, $sDate . $oImage->getClientOriginalName())) {
         //Asset will give you the directory of public folders, that will be used in saving photos to it!
         //  dd(asset($oImage->getClientOriginalName()));
         return asset($sDestination . $sDate . $oImage->getClientOriginalName());
     } else {
         return false;
     }
 }
 public function postUpdateProduct()
 {
     $input = \Request::all();
     $id = $input['id'];
     $update_array = ["product_name" => $input['product_name'], "count" => $input['count'], "buy_cost" => $input['buy_cost'], "sell_cost" => $input['sell_cost'], "desc" => $input['desc'], "cate" => $input['cate']];
     if (\Request::hasFile("product_img")) {
         //            dd($input);
         $img_save_path = real_imgs_dir . "selling-manager";
         $product_img_name = $this->upload_file(\Request::file("product_img"), $img_save_path);
         $update_array["product_img"] = $product_img_name;
     }
     \Selling_Manager_Products_Model::find($id)->update($update_array);
     return \Redirect::back();
 }
コード例 #20
0
ファイル: CrudAttachController.php プロジェクト: skvn/crud
 public function upload()
 {
     if (\Request::hasFile('file')) {
         $file = \Request::file('file');
         if ($file instanceof UploadedFile) {
             $crud_file = CrudFile::createFromUpload($file);
             $ret = ['id' => $crud_file->id, 'url' => $crud_file->getDownloadLinkAttribute()];
             if (strpos($crud_file->mime_type, 'image') !== false) {
                 $dimensions = getimagesize($crud_file->path);
                 $ret['width'] = $dimensions[0];
                 $ret['height'] = $dimensions[1];
             }
             return $ret;
         }
     }
 }
コード例 #21
0
ファイル: ResourceController.php プロジェクト: jay4497/j4cms
 public function postUpload($type)
 {
     $result = [];
     if (count($_FILES) <= 0) {
         $result['status'] = 'failed';
         $result['msg'] = 'no file';
         return response(json_encode($result))->header('Content-Type', 'application/json');
     }
     $files = \Request::file();
     switch ($type) {
         case 'image':
             $img = new J4Image();
             $result = $img->upload($files, 'assets/images/upload', true, false);
             break;
     }
     return response(json_encode($result))->header('Content-Type', 'application/json');
 }
コード例 #22
0
 public function postRegister(Request $request)
 {
     if ($request->ajax()) {
         if (User::create($request->all())) {
             $file = \Request::file('documento');
             $storagePath = storage_path() . '/documentos/';
             $fileName = $file->getClientOriginalName();
             $file->move($storagePath, $fileName);
             //return redirect('http://www.google.com.br');
             // return response()->json([
             //     'message' => 'success'
             // ]);
         }
     }
     // if( ) ){
     //     dd( \Request::all() );
     // }
 }
コード例 #23
0
 public function update(PromocionesRequest $request, $id)
 {
     try {
         $promocion = Promocion::findOrFail($id);
         $input = $request->all();
         $imagen = \Request::file('imagen');
         if ($imagen) {
             \File::delete($promocion->get_path_imagen());
             $nombre_imagen = save_file($imagen, path_promociones());
             $input['imagen'] = $nombre_imagen;
         }
         $promocion->update($input);
         \Session::flash('noticia', 'La promoci&oacute;n con nombre "' . $promocion . '" fue actualizada con &eacute;xito.');
     } catch (ModelNotFoundException $e) {
         \Session::flash('error', 'La promoci&oacute;n no existe en la base de datos.');
     }
     return redirect('administracion/promociones');
 }
コード例 #24
0
 public function update(CategoriasRequest $request, $id)
 {
     try {
         $categoria = Categoria::findOrFail($id);
         $input = $request->all();
         $imagen = \Request::file('imagen');
         if ($imagen) {
             \File::delete($categoria->get_path_imagen());
             $nombre_imagen = save_file($imagen, path_categorias());
             $input['imagen'] = $nombre_imagen;
         }
         $categoria->update($input);
         \Session::flash('noticia', 'La categor&iacute;a con nombre "' . $categoria . '" fue actualizada con &eacute;xito.');
     } catch (ModelNotFoundException $e) {
         \Session::flash('error', 'La categor&iacute;a no existe en la base de datos.');
     }
     return redirect('administracion/categorias');
 }
コード例 #25
0
 public function store()
 {
     if (\Request::file('cover')->isValid()) {
         $file = \Request::file('cover');
         $destinationPath = './images';
         //public_path() .
         $extension = \Request::file('cover')->getClientOriginalExtension();
         $filename = rand(1111111, 9999999) . '.' . $extension;
         $file->move($destinationPath, $filename);
         $image = \App\Image::create(['path' => './images/' . $filename, 'description' => 'main']);
     } else {
         return redirect()->back()->withInput()->with('message', 'image file invalid');
     }
     $book = \App\Book::create(['title' => \Request::get('title'), 'isbn' => \Request::get('isbn'), 'price' => \Request::get('price'), 'cover' => $filename]);
     $book->images()->attach($image->id);
     $book->Author()->attach(\Request::get('author_id'));
     $book->categories()->attach(\Request::get('category'));
     return redirect('./admin/products')->with('message', 'product created');
 }
コード例 #26
0
ファイル: UserController.php プロジェクト: bdgeek/laraproto
 /**
  * Save current user
  * 
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function profileSave(Request $request)
 {
     $user = \Auth::user();
     $validator = \Validator::make($request->all(), ['name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users,email,' . $user->id, 'password' => 'confirmed|min:6']);
     // When fails
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     // When succeeds
     $user->update($request->all());
     if (!empty($request->get('password'))) {
         $user->password = \Hash::make($request->get('password'));
         $user->save();
     }
     // Process avatar
     $user->saveAvatar(\Request::file('avatar'), $request->get('image_max_width'));
     \Session::set('status', 'Settings saved');
     return \Redirect::to('admin/profile');
 }
コード例 #27
0
 public function store(CreateProductoRequest $request)
 {
     $path = 'uploads/imagenes';
     $file = \Request::file('imagen');
     $archivo = $file->getClientOriginalName();
     $uploads = $file->move($path, $irchivo);
     //if(uploads){
     //Request::file('imagen')->move($path);
     // $inputs=Request::all();
     Producto::create($request->all());
     //Imagen::create($inputs);
     //agregado
     $inputs = Input::All();
     $n = new Imagen();
     $n->id_producto = $inputs['id_producto'];
     $n->ruta_imagen = $archivo;
     $n->save();
     return redirect('/productos');
     //}
 }
コード例 #28
0
 public function uploadCsv(Request $request)
 {
     if (Request::isMethod('post')) {
         $validator = Validator::make(Input::all(), AdminTool::$uploadCsvRules);
         if ($validator->passes()) {
             $file = \Request::file('yourcsv');
             //the files are stored in storage/app/*files*
             $output = Storage::put('yourcsv.csv', file_get_contents($file));
             if ($output) {
                 $this->dispatch(new ImportCSV());
                 return Redirect::to('admin/uploadcsv')->with('message', 'The following errors occurred')->withErrors('Your file has been successfully uploaded. You will receive an email notification once the import is completed.');
             } else {
                 return Redirect::to('admin/uploadcsv')->with('message', 'The following errors occurred')->withErrors('Something went wrong with your upload. Please try again.');
             }
         } else {
             return Redirect::to('admin/uploadcsv')->with('message', 'The following errors occurred')->withErrors($validator)->withInput();
         }
     }
     return view('admin/uploadcsv');
 }
コード例 #29
0
 /**
  * Save brand
  * 
  * @return \Illuminate\Http\JsonResponse
  */
 public function save()
 {
     $input = \Input::except('_token');
     $input['active'] = empty($input['active']) ? 0 : 1;
     // Validate
     $validator = \Validator::make($input, ['name' => 'required|max:255']);
     // When fails
     if ($validator->fails()) {
         return response()->json(['errors' => $validator->messages()]);
     }
     // Save changes
     $brand = Brand::findOrNew($input['id']);
     // Uncheck other brands default value
     if ($input['active']) {
         \DB::table('brands')->update(['active' => 0]);
     }
     $brand->fill($input);
     $brand->save();
     // Process logo image
     if ($picture = \Request::file('file-0')) {
         $filename = 'picture.' . $picture->getClientOriginalExtension();
         $picture->move(public_path($brand->getStoragePath()), $filename);
         $brand->logo = $filename;
         $brand->save();
     }
     // At least 1 brand must be active
     if (\DB::table('brands')->where('active', 1)->count() == 0) {
         $first = \DB::table('brands')->first();
         \DB::table('brands')->where('id', $first->id)->update(['active' => 1]);
     }
     try {
         // Save active css
         $active = Brand::where('active', 1)->first();
         file_put_contents($active->getCssPath(), $active->css);
         // Response
         return response()->json(['success' => 'Brand saved', 'redirect' => url('/admin/brands/list')]);
     } catch (\Exception $e) {
         // Response
         return response()->json(['success' => false, 'errors' => ['css' => ['Failed saving css']]]);
     }
 }
コード例 #30
0
ファイル: NewsController.php プロジェクト: visavi/rotorcms
 /**
  * Создание новости
  */
 public function create()
 {
     if (!User::isAdmin()) {
         App::abort('403');
     }
     if (Request::isMethod('post')) {
         $news = new News();
         $news->category_id = Request::input('category_id');
         $news->user_id = User::get('id');
         $news->title = Request::input('title');
         $news->slug = '';
         $news->text = Request::input('text');
         $image = Request::file('image');
         if ($image && $image->isValid()) {
             $ext = $image->getClientOriginalExtension();
             $filename = uniqid(mt_rand()) . '.' . $ext;
             if (in_array($ext, ['jpeg', 'jpg', 'png', 'gif'])) {
                 $img = new SimpleImage($image->getPathName());
                 $img->best_fit(1280, 1280)->save('uploads/news/images/' . $filename);
                 $img->best_fit(200, 200)->save('uploads/news/thumbs/' . $filename);
             }
             $news->image = $filename;
         }
         if ($news->save()) {
             if ($tags = Request::input('tags')) {
                 $tags = array_map('trim', explode(',', $tags));
                 foreach ($tags as $tag) {
                     $tag = Tag::create(['name' => $tag]);
                     $tag->create_news_tags(['news_id' => $news->id]);
                 }
             }
             App::setFlash('success', 'Новость успешно создана!');
             App::redirect('/' . $news->category->slug . '/' . $news->slug);
         } else {
             App::setFlash('danger', $news->getErrors());
             App::setInput($_POST);
         }
     }
     $categories = Category::getAll();
     App::view('news.create', compact('categories'));
 }