Advertisement
villers

Untitled

Sep 23rd, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2.     public function store()
  3.     {
  4.         if(!Auth::check())
  5.             return Redirect::to('/annonce/all')
  6.                 ->with('message', 'Vous devez etre connecté pour acceder a cette page');
  7.  
  8.         $validator = Validator::make(Input::all(), Annonce::$rules);
  9.         if ($validator->fails())
  10.             return Redirect::to('annonce/create')
  11.                 ->withErrors($validator)
  12.                 ->withInput();
  13.         else {
  14.             $annonce = new Annonce;
  15.             $annonce->title             = Input::get('title');
  16.             $annonce->description       = Input::get('description');
  17.             $annonce->prix              = Input::get('prix');
  18.             $annonce->tags              = Input::get('tags');
  19.             $annonce->ville             = Input::get('ville');
  20.             $annonce->user_id           = Auth::user()->id;
  21.             $annonce->save();
  22.  
  23.             if(Input::hasFile('files'))
  24.                 foreach (Input::file('files') as $file) {
  25.                     $path = strtolower(public_path('uploads'.DIRECTORY_SEPARATOR.$annonce->id));
  26.                     $filename = strtolower($file->getClientOriginalName());
  27.                     $extension = strtolower($file->getClientOriginalExtension());
  28.                     $mime = $file->getMimeType();
  29.  
  30.                     $upload = new Upload;
  31.                     $upload->user_id            = Auth::user()->id;
  32.                     $upload->annonce_id         = $annonce->id;
  33.                     $upload->nom                = $filename;
  34.                     $upload->save();
  35.  
  36.                     $file->move($path, $filename);
  37.                 }
  38.  
  39.             return Redirect::to('/annonce')
  40.                 ->with('message', 'L\'annonce a été crée');
  41.         }
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement