<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Bioabout;
use App\Helper\admin\ImageUpload;

class BioController extends Controller
{
    //

    public function showbio(){

        $alldata = Bioabout::all();
        
        return view('admin.pages.about.showbio',compact('alldata'));
    }


    public function editbio($id){

        $edata = Bioabout::find($id);

        return view('admin.pages.about.editbio',compact('edata'));
    }


    public function updatebio(Request $request, $id){


        $blogs = Bioabout::find($id);
        $old = $blogs->image;
        if ($request->hasFile('image')){
            $file = $request->file('image');
            $path = "upload/bio/bioimage/";
            $filename = ImageUpload::updateImage($old, $path, $file);
            $image_name = $path.$filename;
        }else{
            $image_name = $old;
        }

        $blogs->heading1 = $request->get('heading1');
        $blogs->heading2 = $request->get('heading2');
        $blogs->image = $image_name;
        $blogs->content = $request->get('content');
        $blogs->save();
        return redirect()->route('admin::show_bio')->with('success','Edited Successfully');

    }

}
