Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public function store()
- {
- if(!Auth::check())
- return Redirect::to('/annonce/all')
- ->with('message', 'Vous devez etre connecté pour acceder a cette page');
- $validator = Validator::make(Input::all(), Annonce::$rules);
- if ($validator->fails())
- return Redirect::to('annonce/create')
- ->withErrors($validator)
- ->withInput();
- else {
- $annonce = new Annonce;
- $annonce->title = Input::get('title');
- $annonce->description = Input::get('description');
- $annonce->prix = Input::get('prix');
- $annonce->tags = Input::get('tags');
- $annonce->ville = Input::get('ville');
- $annonce->user_id = Auth::user()->id;
- $annonce->save();
- if(Input::hasFile('files'))
- foreach (Input::file('files') as $file) {
- $path = strtolower(public_path('uploads'.DIRECTORY_SEPARATOR.$annonce->id));
- $filename = strtolower($file->getClientOriginalName());
- $extension = strtolower($file->getClientOriginalExtension());
- $mime = $file->getMimeType();
- $upload = new Upload;
- $upload->user_id = Auth::user()->id;
- $upload->annonce_id = $annonce->id;
- $upload->nom = $filename;
- $upload->save();
- $file->move($path, $filename);
- }
- return Redirect::to('/annonce')
- ->with('message', 'L\'annonce a été crée');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement