Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function up()
- {
- Schema::create('images', function (Blueprint $table) {
- $table->increments('id');
- $table->string('image');
- $table->integer('product_id')->nullable()->unsigned();
- $table->timestamps();
- });
- Schema::table('images', function($table) {
- $table->foreign('product_id')->references('id')->on('products');
- });
- }
- <div class="row">
- <div class="col-md-12">
- {!! Form::open([ 'route' => [ 'dropzone.store' ], 'files' => true, 'enctype' => 'multipart/form-data', 'class' => 'dropzone', 'id' => 'image-upload' ]) !!}
- {{ csrf_field() }}
- <div>
- <h4 style="text-align: center;color:#428bca;">Drop images in this area <span class="glyphicon glyphicon-hand-down"></span></h4>
- <!-- Input code below Not working yet -->
- <input type="text" name="product_id" value="" hidden>
- </div>
- {!! Form::close() !!}
- </div>
- </div>
- <!-- drozone -->
- <script type="text/javascript">
- Dropzone.options.imageUpload = {
- maxFilesize: 5, //MB
- acceptedFiles: ".jpeg,.jpg,.png,.gif"
- };
- </script>
- <?php
- namespace AppHttpControllers;
- use IlluminateHttpRequest;
- use AppImage;
- use AppProduct;
- class ImageController extends Controller
- {
- public function dropzone()
- {
- return view('dropzone-view');
- }
- public function dropzoneStore(Request $request)
- {
- $image = $request->file('file');
- $imageName = time().$image->getClientOriginalName();
- $image->move(public_path('images'),$imageName);
- return response()->json(['success'=>$imageName]);
- }
- }
- Route::get('dropzone', 'ImageController@dropzone');
- Route::post('dropzone/store', ['as'=>'dropzone.store','uses'=>'ImageController@dropzoneStore']);
Add Comment
Please, Sign In to add comment