Guest User

Untitled

a guest
Nov 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. public function up()
  2. {
  3. Schema::create('images', function (Blueprint $table) {
  4. $table->increments('id');
  5. $table->string('image');
  6. $table->integer('product_id')->nullable()->unsigned();
  7. $table->timestamps();
  8. });
  9.  
  10. Schema::table('images', function($table) {
  11. $table->foreign('product_id')->references('id')->on('products');
  12. });
  13. }
  14.  
  15. <div class="row">
  16. <div class="col-md-12">
  17. {!! Form::open([ 'route' => [ 'dropzone.store' ], 'files' => true, 'enctype' => 'multipart/form-data', 'class' => 'dropzone', 'id' => 'image-upload' ]) !!}
  18. {{ csrf_field() }}
  19. <div>
  20. <h4 style="text-align: center;color:#428bca;">Drop images in this area <span class="glyphicon glyphicon-hand-down"></span></h4>
  21. <!-- Input code below Not working yet -->
  22. <input type="text" name="product_id" value="" hidden>
  23. </div>
  24. {!! Form::close() !!}
  25. </div>
  26. </div>
  27.  
  28. <!-- drozone -->
  29. <script type="text/javascript">
  30. Dropzone.options.imageUpload = {
  31. maxFilesize: 5, //MB
  32. acceptedFiles: ".jpeg,.jpg,.png,.gif"
  33. };
  34. </script>
  35.  
  36. <?php
  37.  
  38. namespace AppHttpControllers;
  39.  
  40. use IlluminateHttpRequest;
  41. use AppImage;
  42. use AppProduct;
  43.  
  44. class ImageController extends Controller
  45. {
  46. public function dropzone()
  47. {
  48. return view('dropzone-view');
  49. }
  50.  
  51. public function dropzoneStore(Request $request)
  52. {
  53. $image = $request->file('file');
  54. $imageName = time().$image->getClientOriginalName();
  55. $image->move(public_path('images'),$imageName);
  56. return response()->json(['success'=>$imageName]);
  57. }
  58. }
  59.  
  60. Route::get('dropzone', 'ImageController@dropzone');
  61. Route::post('dropzone/store', ['as'=>'dropzone.store','uses'=>'ImageController@dropzoneStore']);
Add Comment
Please, Sign In to add comment