app/Http/Controllers/Admin/BidsController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Tender $tender, Request $request)
    {
        $this->validate($request, [
            'company_name' => 'bail|required|string',
            'ntn_number' => 'bail|required|string|unique:bids',
            'experience' => 'bail|required',
            'amount' => 'bail|required',
            'contact_person' => 'bail|required|string',
            'email' => 'bail|required|email',
            'contact_no' => 'bail|required|numeric|min:11',
           'upload_file' => 'bail|required|file|mimes:pdf,doc,ppt,xls,docx,pptx,xlsx|max:8192' 
        ]);
        if ($tender->bids()->where('ntn_number', $request->ntn_number)->exists()) {
            return Redirect()->back()->with(['company_exist' => 'You Already bid against this tender, Multiple bid against same tender are not allowed...!']);
        }else{
            $userId = \Auth::user()->id;
            if(request()->hasFile('upload_file')){
                $sizeInBytes = request()->file('upload_file')->getSize();
                $filenamewithextension = request()->file('upload_file')->getClientOriginalName();
                $filename = pathinfo($filenamewithextension, PATHINFO_FILENAME);
                $filename = rand(000,999).'_'.uniqid();
                $extension = request()->file('upload_file')->getClientOriginalExtension();
                $filenametostore = $filename.'.'.$extension;
                $path = Storage::disk('local')->put($filenametostore, fopen(request()->file('upload_file'), 'r+'));
            }
            $tender->bids()->create([
                'company_name' => Crypt::encryptString($request->company_name),
                'ntn_number' => $request->ntn_number,
                'experience' => Crypt::encryptString($request->experience),
                'amount' =>     Crypt::encryptString($request->amount),
                'contact_person' => Crypt::encryptString($request->contact_person),
                'email' => Crypt::encryptString($request->email),
                'contact_no' => Crypt::encryptString($request->contact_no),
                'upload_file' => $filenametostore,
                'extension' => $extension,
                'user_id' => $userId
            ]);
            Toastr::success('Data Created Successfully', 'Success', ['positionClass' => 'toast-top-right']);
            if($request->has('from_bider')){
                return redirect()->route('tenders'); 
            }else{
                return redirect()->route('tenders.bids.index',$tender->id); 
            } 
        }
    }
public function store ( Tender $ tender , Request $ request ) { $ this -> validate ( $ request , [ 'company_name' => 'bail|required|string' , 'ntn_number' => 'bail|required|string|unique:bids' , 'experience' => 'bail|required' , 'amount' => 'bail|required' , 'contact_person' => 'bail|required|string' , 'email' => 'bail|required|email' , 'contact_no' => 'bail|required|numeric|min:11' , 'upload_file' => 'bail|required|file|mimes:pdf,doc,ppt,xls,docx,pptx,xlsx|max:8192' ] ) ; if ( $ tender -> bids ( ) -> where ( 'ntn_number' , $ request -> ntn_number ) -> exists ( ) ) { return Redirect ( ) -> back ( ) -> with ( [ 'company_exist' => 'You Already bid against this tender, Multiple bid against same tender are not allowed...!' ] ) ; } else { $ userId = \ Auth :: user ( ) -> id ; if ( request ( ) -> hasFile ( 'upload_file' ) ) { $ sizeInBytes = request ( ) -> file ( 'upload_file' ) -> getSize ( ) ; $ filenamewithextension = request ( ) -> file ( 'upload_file' ) -> getClientOriginalName ( ) ; $ filename = pathinfo ( $ filenamewithextension , PATHINFO_FILENAME ) ; $ filename = rand ( 000 , 999 ) . '_' . uniqid ( ) ; $ extension = request ( ) -> file ( 'upload_file' ) -> getClientOriginalExtension ( ) ; $ filenametostore = $ filename . '.' . $ extension ; $ path = Storage :: disk ( 'local' ) -> put ( $ filenametostore , fopen ( request ( ) -> file ( 'upload_file' ) , 'r+' ) ) ; } $ tender -> bids ( ) -> create ( [ 'company_name' => Crypt :: encryptString ( $ request -> company_name ) , 'ntn_number' => $ request -> ntn_number , 'experience' => Crypt :: encryptString ( $ request -> experience ) , 'amount' => Crypt :: encryptString ( $ request -> amount ) , 'contact_person' => Crypt :: encryptString ( $ request -> contact_person ) , 'email' => Crypt :: encryptString ( $ request -> email ) , 'contact_no' => Crypt :: encryptString ( $ request -> contact_no ) , 'upload_file' => $ filenametostore , 'extension' => $ extension , 'user_id' => $ userId ] ) ; Toastr :: success ( 'Data Created Successfully' , 'Success' , [ 'positionClass' => 'toast-top-right' ] ) ; if ( $ request -> has ( 'from_bider' ) ) { return redirect ( ) -> route ( 'tenders' ) ; } else { return redirect ( ) -> route ( 'tenders.bids.index' , $ tender -> id ) ; } } }
Store a newly created resource in storage.
Store a newly created resource in storage .
// $encrypted = Crypt::encryptString('Hello world'); // $decrypted = Crypt::decryptString($encrypted); // dd($encrypted. ' '. $decrypted); //8mb //dd($request->toArray()); //get filename without extension //get file extension //filename to store