Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. <p>Upload Youre Photos Here:</p>
  2. <form action="{{ route('photos.store') }}" method="POST"
  3. class="dropzone"
  4. id="addPhotosForm">
  5. {{ csrf_field() }}
  6. </form>
  7.  
  8. public function store(Request $request, Banner $banner)
  9. {
  10. $file = $request->file('file');
  11. $name = time() . $file->getClientOriginalName();
  12. $file->move('banner/photos', $name);
  13. Photo::create([
  14. 'path' => "banner/photos/{$name}",
  15. 'banner_id' => $banner->id,
  16. 'name' => $name,
  17. ]);
  18.  
  19. return 'Done';
  20. }
  21.  
  22. SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'banner_id' cannot be null (SQL: insert into `photos` (`path`, `banner_id`, `name`, `updated_at`, `created_at`) values (banner/photos/1474787058014ed562a8f945428240a83dbc8baa0d.jpg, , 1474787058014ed562a8f945428240a83dbc8baa0d.jpg, 2016-09-25 07:04:18, 2016-09-25 07:04:18))
  23.  
  24. init: function () {
  25. this.on('sending', function (file, xhr, formData) {
  26. formData.append("banner_id", 1);
  27. });
  28. this.on("success", function (file) {
  29. swal({
  30. title: "Success",
  31. text: "Your Photo has been uploaded!",
  32. type: "success",
  33. timer: 2000,
  34. showConfirmButton: false,
  35. });
  36. window.setTimeout(function () {
  37. location.reload();
  38. }, 2000)
  39. });
  40.  
  41. },
  42.  
  43.  
  44. };
  45.  
  46.  
  47. </script>`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement