Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

after submitting form data, page not being properly loaded in laravel

i have a website in which there is a form, the form data after user submits is sent to my database and email.

below is my controller and route

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Register;
use App\Mail\SendEmail;
use Session;
use Mail;
use Storage;
use Illuminate\Support\Facades\File;

class RegController extends Controller
{

    public function index()
    {
        //
    }


    public function create()
    {
        //
    }

    public function store(Request $request)
    {

       // return $request;


// return $request->Fee;
            $data = new Register;
            $data->firstname = $request->firstname;
            $data->lastname = $request->lastname;
            $data->mobilenumber = $request->mobilenumber;
            $data->experience = $request->experience;
            $data->designation = $request->designation;
            $data->confirmation = $request->confirmation;
            $data->company = $request->company;
            $data->address = $request->address;
            $data->addressline2 = $request->addressline2;
            $data->city = $request->city;
            $data->state = $request->state;
            $data->pin = $request->pin;
            $data->country = $request->country;
            $data->Whatsapp = $request->Whatsapp;
            $data->alternatenumber = $request->alternatenumber;
            $data->Email = $request->Email;
            $data->CompanyRegNumber = $request->CompanyRegNumber;
            $data->Date_Incorporation_orBusi_Stp = $request->Date_Incorporation_orBusi_Stp;
            $data->GSTIN = $request->GSTIN;
            $data->Services_Offered = $request->Services_Offered;
            $data->Annual_Turnover = $request->Annual_Turnover;
            $data->Declaration = $request->Declaration;

            $data->termsandconditions = $request->termsandconditions;
            // $data->Fee = $request->Fee;
            $data->Mode_of_Payment = $request->Mode_of_Payment;

            $data->Recommended_by_A = $request->Recommended_by_A;
            $data->Recommended_by_B = $request->Recommended_by_B;

              $fee = $request->Fee[0];
              $data->Fee = $fee;

              if(!empty($request->Fee[1]))
              {
               $data->Fee1 = $request->Fee[1];
              }
              if(!empty($request->Fee[2]))
              {
               $data->Fee2 = $request->Fee[2];
              }
            if(!empty($request->Fee[3]))
              {
               $data->Fee3 = $request->Fee[3];
              }


 if($request->hasFile('Photo')) {
      $image = $request->file('Photo');
      $filename = time().$image->getClientOriginalName();
      $destinationPath = public_path('uploads/Photo');

     Storage::disk('public')->put($filename,  File::get($image));
      $data->Photo=$filename;
    }
 if($request->hasFile('Receipt')) {
      $image = $request->file('Receipt');
      $filename = time().$image->getClientOriginalName();
      $destinationPath = public_path('uploads/Receipt');
    Storage::disk('public')->put($filename,  File::get($image));
      $data->Receipt=$filename;
    }
 if($request->hasFile('Signature')) {
      $image = $request->file('Signature');
      $filename = time().$image->getClientOriginalName();
      $destinationPath = public_path('uploads/Signature');
      Storage::disk('public')->put($filename,  File::get($image));
      $data->Signature=$filename;
    }

            $data->save();
            Session::flash('registered','reg');


        $name = $request->firstname." ".$request->lastname;
        $subject = "TEIA";
        $message =  $data->id;

         $photo = $data->Photo;
         $sign = $data->Signature;
         $recipt= $data->Receipt;
    $email = '[email protected]';


        // ->cc(['[email protected]','[email protected]'])
      Mail::to($email)->send( new SendEmail($subject,$message , $photo ,$sign,$recipt));




            return back();
    }


    public function show($id)
    {
        //
    }


    public function edit($id)
    {
        //
    }


    public function update(Request $request, $id)
    {
        //
    }


    public function destroy($id)
    {
        //
    }
}

Route::get('/', function () {
	// Session::flush();
    return view('welcome');
});
Route::resource('register','RegController');

after the user submits the register button, the data is submitted and then the user is taken to the form with succes message on top. the problem is first time when the user submits the data, the the page gets stuck at https://booktheparty.in/TEIA/register with blank page. then when the user go back and submit again, then the page is directed to form page and shws succs message. but still the data is added 2 times to database. i want to know why my page gets stuck at the first time. can anyone tell me

like image 459
subah shaam Avatar asked Nov 07 '22 16:11

subah shaam


1 Answers

Please replace this code with your store function

 public function store(Request $request)
    {

       // return $request;


// return $request->Fee;
            $data = new Register;
            $data->firstname = $request->firstname;
            $data->lastname = $request->lastname;
            $data->mobilenumber = $request->mobilenumber;
            $data->experience = $request->experience;
            $data->designation = $request->designation;
            $data->confirmation = $request->confirmation;
            $data->company = $request->company;
            $data->address = $request->address;
            $data->addressline2 = $request->addressline2;
            $data->city = $request->city;
            $data->state = $request->state;
            $data->pin = $request->pin;
            $data->country = $request->country;
            $data->Whatsapp = $request->Whatsapp;
            $data->alternatenumber = $request->alternatenumber;
            $data->Email = $request->Email;
            $data->CompanyRegNumber = $request->CompanyRegNumber;
            $data->Date_Incorporation_orBusi_Stp = $request->Date_Incorporation_orBusi_Stp;
            $data->GSTIN = $request->GSTIN;
            $data->Services_Offered = $request->Services_Offered;
            $data->Annual_Turnover = $request->Annual_Turnover;
            $data->Declaration = $request->Declaration;

            $data->termsandconditions = $request->termsandconditions;
            // $data->Fee = $request->Fee;
            $data->Mode_of_Payment = $request->Mode_of_Payment;

            $data->Recommended_by_A = $request->Recommended_by_A;
            $data->Recommended_by_B = $request->Recommended_by_B;

              $fee = $request->Fee[0];
              $data->Fee = $fee;

              if(!empty($request->Fee[1]))
              {
               $data->Fee1 = $request->Fee[1];
              }
              if(!empty($request->Fee[2]))
              {
               $data->Fee2 = $request->Fee[2];
              }
            if(!empty($request->Fee[3]))
              {
               $data->Fee3 = $request->Fee[3];
              }


 if($request->hasFile('Photo')) {
      $image = $request->file('Photo');
      $filename = time().$image->getClientOriginalName();
      $destinationPath = public_path('uploads/Photo');

     Storage::disk('public')->put($filename,  File::get($image));
      $data->Photo=$filename;
    }
 if($request->hasFile('Receipt')) {
      $image = $request->file('Receipt');
      $filename = time().$image->getClientOriginalName();
      $destinationPath = public_path('uploads/Receipt');
    Storage::disk('public')->put($filename,  File::get($image));
      $data->Receipt=$filename;
    }
 if($request->hasFile('Signature')) {
      $image = $request->file('Signature');
      $filename = time().$image->getClientOriginalName();
      $destinationPath = public_path('uploads/Signature');
      Storage::disk('public')->put($filename,  File::get($image));
      $data->Signature=$filename;
    }

            $data->save();
            Session::flash('registered','reg');


        $name = $request->firstname." ".$request->lastname;
        $subject = "TEIA";
        $message =  $data->id;

         $photo = $data->Photo;
         $sign = $data->Signature;
         $recipt= $data->Receipt;
    $email = '[email protected]';


        // ->cc(['[email protected]','[email protected]'])
      Mail::to($email)->send( new SendEmail($subject,$message , $photo ,$sign,$recipt));




            return redirect()->back();
    }

Hope it will work for you

like image 154
Boni Avatar answered Nov 14 '22 22:11

Boni