mardi 7 février 2017

Retrieving the Image on Welcome blade stored by base64_image Field in laravel Backpack

Retrieving the Encrypted Image on welcome blade stored by base64_image Field in laravel Backpack Administration Panel.

I made SliderPhotoCrud with database_table slider_photos and fields are (id,title,image_path). images_path stores image in encrypted format by base64_image field and moves in "public/uploads" folder, I want to retrieve this image on welcome view but there is decryption error.

My photo model is

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;

class Sliderphoto extends Model
{
    use CrudTrait;



/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/

protected $table = 'slider_photos';
protected $primaryKey = 'id';
public $timestamps = false;
// protected $guarded = ['id'];
protected $fillable = ['title','image_path'];
// protected $hidden = [];
// protected $dates = [];

/*
|--------------------------------------------------------------------------
| FUNCTIONS
|--------------------------------------------------------------------------
*/
public function setImageAttribute($value)
{
    $attribute_name = "image_path";
    $disk = "public";
    $destination_path = "/";

    $this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path);
}

/*
|--------------------------------------------------------------------------
| RELATIONS
|--------------------------------------------------------------------------
*/

/*
|--------------------------------------------------------------------------
| SCOPES
|--------------------------------------------------------------------------
*/

/*
|--------------------------------------------------------------------------
| ACCESORS
|--------------------------------------------------------------------------
*/

/*
|--------------------------------------------------------------------------
| MUTATORS
|--------------------------------------------------------------------------
*/

}

Controller is

<?php

namespace App\Http\Controllers\Admin;
use URL;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Intervention\Image\ImageManagerStatic as Image;
// VALIDATION: change the requests to match your own file names if you need form validation
use App\Http\Requests\SliderphotoRequest as StoreRequest;
use App\Http\Requests\SliderphotoRequest as UpdateRequest;

class SliderphotoCrudController extends CrudController {



public function setUp() {

            /*
            |--------------------------------------------------------------------------
            | BASIC CRUD INFORMATION
            |--------------------------------------------------------------------------
            */
            $this->crud->setModel("App\Models\Sliderphoto");
            $this->crud->setRoute("admin/sliderphoto");
            $this->crud->setEntityNameStrings('Slider Photo', 'Slider Photos');

            $this->crud->setColumns(['title','image_path']);
            /*
            |--------------------------------------------------------------------------
            | BASIC CRUD INFORMATION
            |--------------------------------------------------------------------------
            */
            $this->crud->addField([    
                                    'name' => 'title',
                                    'label' => 'Enter title',
                                    'type' => 'text',
                                    'placeholder' => 'Enter Title Here',
                                ]);
            $this->crud->addField(
                [   // Browse
                'name' => 'image_path',
                'label' => 'Image',
                'filename' => "image_filename",
                'type' => 'base64_image',

                'upload' => true,
                'crop' => true, // set to true to allow cropping, false to disable
                'aspect_ratio' => 2,
                'disk' => 'uploads',]
            );

            //$this->crud->setFromDb();
        }

        public function store(StoreRequest $request)
        {
            //echo $request->input('image_path') . "<br>";
            //echo $request->input('image_filename') . "<br>";
            //echo "<br>" . $request->input('filename');
            $imageFilename = $request->input('image_filename');
            //echo "<br>" . $request->input('image_path');

            //$request->replace(['image_path'=>$request->input('image_filename')]);
            if ($imageFilename !== ''){ 
               //echo $imageFilename = uniqid('image_path');

                //echo $imageFilename . "<br>";
                //dd($storagePath);
                /*echo URL::asset("/public/uploads");
                echo public_path('uploads/');*/
               // echo $imageFilename->getClientOriginalName();
              //  die();

                //$imageFilename =substr($imageFilename, -22);
                  Image::make($request->input('image_path'))->save(public_path('uploads/') .$imageFilename);
            }
            return parent::storeCrud();
        }

        public function update(UpdateRequest $request)
        {
            $imageFilename = $request->input('image_filename');

            /*  if ($imageFilename !== ''){ `enter code here`
                $imageFilename = uniqid('image_').'.png'; 
                Image::make($request->input('image'))->resize(200,200)->save($storagePath.$imageFilename);
                $user->addMedia($storagePath.$imageFilename)->toCollection('image');
            }
            return parent::updateCrud();*/
        }
    }



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2kNWavP
via IFTTT

Aucun commentaire:

Enregistrer un commentaire