Home > OS >  can I use one table in database for two forms in Laravel
can I use one table in database for two forms in Laravel

Time:08-25

*

Hi, 
    I'm using two forms for that I want only one database table can I do this ?
     
    my attempt for getting this are--
    
   Routes --
    
        Route::get('/Form1', [Form1Controller::class, 'index']);
                    Route::post('/store-form', [Form2Controller::class, 'Register']);
    
                    Route::get('/Form2', [Form2Controller::class, 'index']);
                    Route::post('/store-form', [Form2Controller::class, 'Register']);   
    
    controller--
    <?PHP
    
    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    use App\Models\form2;
    
    class Form2Controller extends Controller
    {
        public function index()
        {
            return view('form2');
        }
    
        public function Register(Request $request)
        {
    
            $request -> validate([
    
                ' Name'  => 'required',            
                'pan'  => 'required',
                'Address' => 'required|max:60',
                'Email' => 'required',          
                'Mobile' => 'required|digits:10',           
                'Amount' => 'required|min:2',  
             
    
    
                ]);     
                    
                    
                        $Form2 = new Form2;
                        $Form2->Name = $request->Name;
                        $Form2->pan = $request->pan;
                        $Form2->Address = $request->Address; 
                        $Form2->Email = $request->Email;
                        $Form2->Mobile = $request->Mobile;                 
                        $Form2->Amount = $request->Amount;  
                      
      
    
                      
                        $Form2->save();
                     return redirect('/Form2')->with('status', 'Donation Done ');   
                    }     
                  
            }
       
    
    Model-- 
    
    <?PHP
    
    namespace App\Models;
    
    use Illuminate\Database\Eloquent\Factories\Has Factory;
    use Illuminate\Database\Eloquent\Model;
    use App\http\Controllers\Dummy Controller;
    
    
    class form2 extends Model
    {
        use Has Factory;
    
         protected $list = [      
            'Name',
            'pan',
            'Address',       
            'Email',
            'Mobile',        
            'Amount',
          
    
          
        ];
    }
    
    
    what can I do for this if I have two separate forms and want to join with one database, I'm new to Laravel Please help me for this. 

uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu *

CodePudding user response:

If both forms fields are same, then just use same model for both.

CodePudding user response:

if you use route index in your form always retur view... you need use other route in your form for example in your form1:

Route::post('/store-form', [Form2Controller::class, 'Register']);

and in your form2

Route::post('/store-form', [Form2Controller::class, 'Register']);

but never user in your form routes index or return same view

  • Related