Kaustubh
2 years ago

How to use pg_unescape_bytea

Posted 2 years ago by Kaustubh

I successfully stored file in database (bytea datatype), but when i try to retrive my file it throws error

Method Illuminate\Support\Collection::__toString() must return a string value

My controller

public function index()
{
    $img = DB::table('images')->pluck('file');
    $decode = pg_unescape_bytea($img);
    dd($decode);
    return view('home',compact('decode'));
}

// To store file in database

public function save(Request $req)
{
    $resume = Input::file('file');
    $extenstion = file_get_contents($resume);
    $file = pg_escape_bytea($extenstion);
    $data = array('file' => $file); 
    DB::table('images')->insert($data);
    return redirect()->back();
}

Please sign in or create an account to participate in this conversation.