Skip to content

Instantly share code, notes, and snippets.

@sagar290
Last active May 14, 2019 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagar290/c1790b520c1df716de90ae1546da408f to your computer and use it in GitHub Desktop.
Save sagar290/c1790b520c1df716de90ae1546da408f to your computer and use it in GitHub Desktop.
Get image as base 64 format and insert DB
<?php
class ImageController {
public function addEmployee(Request $request)
{
$pp = $request->pp;
$image_name = '';
if ($pp) {
list($type, $image) = explode(';', $pp);
list(, $image) = explode(',', $image);
$image = base64_decode($image);
$image_name= "https://lms10.s3.ap-southeast-1.amazonaws.com/main/ublbb/pp/".time().".png";
$store = Storage::disk('s3')->put('main/ublbb/pp/'.$image_name, $image, 'public'); //You can use local file by changing the disk('local)
}
$user = new User; // Initialize Model in $user variable
$user->pp = $image_name;
if ($user->save()) {
return 'success';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment