Guest User

Untitled

a guest
Jan 16th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. $messages = [
  2. 'title.required' => 'Desculpe! Campo obrigatório.',
  3. 'title.max' => 'Desculpe! Máximo de 150 caracteres.',
  4. 'text.required' => 'Desculpe! Campo obrigatório, preencha o texto desta notícia',
  5. 'categories.required' => 'Desculpe! Campo obrigatório.',
  6. 'image.required' => 'Desculpe! Campo obrigatório.',
  7. 'image.max' => 'Desculpe! o Arquivo enviado ultrapassa o limite de tamanhos sugerido, tente enviar algo um pouco menor.',
  8. 'image.mimes' => 'Desculpe, o arquivo enviado não é válido, são permitidos arquivos nas extensões jpg, png, jpeg, gif ou vídeos em mp4!',
  9. ];
  10.  
  11. Validator::make($request->all(), [
  12. 'title' => 'required|max:150',
  13. 'text' => 'required',
  14. 'categories' => 'required',
  15. 'image' => 'required|mimes:jpeg,jpeg,png,gif,bmp,mp4|max:104800',//104800
  16. ], $messages)->validate();
  17.  
  18. $news = News::create([
  19. 'title' => $request->get('title'),
  20. 'user_id' => Auth::id(),
  21. 'text' => $request->get('text'),
  22. 'status' => 0
  23. ]);
  24.  
  25. foreach ($request->get('categories') as $order => $category) {
  26. if ($category)
  27. NewsCategory::create([
  28. 'news_id' => $news->id,
  29. 'category_id' => $category,
  30. 'order' => $order,
  31. ]);
  32. }
  33.  
  34. if ($news->id) {
  35. $path = upload_image($request->file('image'), 'news/' . recursive_dir(Auth::id()), true);
  36. NewsImage::create([
  37. 'image' => $path,
  38. 'news_id' => $news->id
  39. ]);
  40.  
  41.  
  42.  
  43. return redirect('/news/draft/' . $news->id)->with('success', 'Notícia salva como rascunho, para publicá-la clique no botão Publicar Agora');
  44. }
  45. }
Add Comment
Please, Sign In to add comment