VaKeR CYBER ARMY
Logo of a company Server : Apache
System : Linux host44.registrar-servers.com 4.18.0-513.18.1.lve.2.el8.x86_64 #1 SMP Sat Mar 30 15:36:11 UTC 2024 x86_64
User : vapecompany ( 2719)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /proc/thread-self/root/home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Backend/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/thread-self/root/home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Backend/CustomerDocumentController.php
<?php

namespace App\Http\Controllers\Backend;

use App\Models\CustomerDocument;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use File;
class CustomerDocumentController extends Controller
{
//   public function __construct()
//     {
//         $this->middleware('auth');
       
//     }
     public function index($type,$id)
    {

        $documents = CustomerDocument::where('document_type',$type)->where('client_id',$id)->get();
        //dd($documents);
        return view('backend.document.index',['documents'=>$documents,'type'=>$type,'id'=>$id]);
    }
    public function create($type,$id)
    {
        return view('backend.document.create',['type'=>$type,'id'=>$id]);
    }
     public function show($type,$id,$id2)
    {
         $documents= CustomerDocument::where('document_type',$type)->where('client_id',$id)->where('document_id',$id2)->first();
         //dd($documents);

          
         $pdf=url('public/images/document/').'/'.$documents->document_file_name;
          $ext =File::extension($pdf);
        $filetype=0;
        if($ext=='pdf'){
            return view('backend.document.viewer',['pdf'=>$pdf]);
            $filetype=1;
        }else{
          $filetype=2;
             return view('backend.document.img_viewer',['pdf'=>$documents->document_file_name,'type'=>$filetype]);
        }
         // response(file_get_contents($pdf),200)
                        //   ->header('Content-Type',$content_types);
         return redirect($pdf);
         

    }
    public function show_document($type,$file){
        if($type==1){
            $pdf=url('public/images/bank_slip').'/'.$file;
        }else if($type==1){
             $pdf=url('public/images/document').'/'.$file;
        }else{
             $pdf=url('public/images').'/'.$file;
        }  
         //$pdf=$request->file;
        $ext =File::extension($pdf);
        if($ext=='pdf'){
            return view('backend.document.viewer',['pdf'=>$pdf]);
        }else{
            //$pdf  = view('document.image',['pdf'=>$pdf]);  
            return view('backend.document.img_viewer',['pdf'=>$file,'type'=>1]);
        }
    }
    public function getImage($type,$file){
        if($type==1){
            $pdf=url('public/images/bank_slip').'/'.$file;
        }else if($type==2){
             $pdf=url('public/images/document').'/'.$file;
        }else{
             $pdf=url('public/images').'/'.$file;
        }  
       return view('backend.document.image',['pdf'=>$pdf]); 
    }

    public function store(Request $request)
    {
      $id=$request->id;
        $validator = \Validator::make($request->all(), [
            
           
            'document_file_name.*' => 'required|mimes:jpeg,pdf,png|max:2048',
           
        ]);
        
        if ($validator->fails())
        {
            return response()->json(['errors'=>$validator->errors()->all()]);
        }else{
          if ($request->hasFile('document_file_name')) {
          
            foreach($request->file('document_file_name') as $k=>$image)
            {
              if(CustomerDocument::first()){
                  $id=CustomerDocument::latest()->first()->document_id+1;
              }        
             //$image = $request->file('document_file_name');
              $new_name = $request->document_name[$k].'_'.$request->type.'_'.$id. '.' . $image->getClientOriginalExtension();
              $image->move(public_path('images/document'), $new_name);
              $documents =  new CustomerDocument;
              $documents->document_name = $request->document_name[$k];
              $documents->document_type = $request->type;
              $documents->client_id = $request->id;
              $documents->document_file_name = $new_name;
            //   $documents->created_by = auth()->user()->user_id;
              $documents->save();  
            }
          }else{
              return response()->json(['errors'=>['imag'=>'File not found']]);
          }
           
        }

        return response()->json(['errors'=>'0','success'=>'Record is successfully added']);
    }
      public function edit($id)
    {
        $documents=CustomerDocument::where('document_id',$id)->first();
        return view('document.edit',['documents'=>$documents]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Brand  $brand
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request)
    {
        $id=$request->document_id;
       $validator = \Validator::make($request->all(), [
           
            'document_type' => 'required',
             'document_file_name' => 'required|image|mimes:jpeg,pdf|max:10000',

           
        ]);
        
        if ($validator->fails())
        {
            return response()->json(['errors'=>$validator->errors()->all()]);
        }else{
           $new_name="";
            if ($request->hasFile('document_file_name')) {
      
                if ($request->file('document_file_name')->isValid()) {
                    $image = $request->file('document_file_name');
                    $new_name = 'document_'.$request->document_id. '.' . $image->getClientOriginalExtension();
                    $image->move(public_path('images'), $new_name);
                }else{
                    return response()->json(['errors'=>['imag'=>'image not valid']]);
                }
            }
            $documents =  CustomerDocument::find($request->document_id);
            $documents->document_type = $request->document_type;
            $documents->document_name = $request->document_name;
            if($new_name != ""){
                $documents->document_file_name = $new_name;
            }
            
            $documents->updated_by = auth()->user()->user_id;
            $documents->save();
        }
        return response()->json(['errors'=>'0','success'=>'Record is successfully Updated']);
    }
    function delete(Request $request){
      $documents =  CustomerDocument::find($request->id);
      $documents->delete();
      return 1;
    }
}

VaKeR 2022