title: Make a Text File Using Laravel and PHP
body: <p>I want to ask a question. I'm new in laravel framework. I want to create a text file from the input form data user using the Laravel framework. while the same time, I want to save these input to my database.</p>
  
  <p>I have success to save in my database. but I fail to create the .txt file from this.</p>
  
  <p>I have tried to get data from database but error. and I just try to get data from input form is an error too.</p>
  
  <p>I've tried...</p>
  
  <pre><code>&lt;?php
  
      $nama     = $_POST['name'];
      $email    = $_POST['email'];
      $dob      = $_POST['date'];
      $phone    = $_POST['phone'];
      $gender   = $_POST['gender'];
      $address  = $_POST['addreess'];
      $date     = date('dmY');
      $jam      = data('his');
  
      $data = "$nama,$email,$dob,$phone,$gender,$address";
      $file = "$nama"-"$date$jam";
      $namafile = "$file.txt";  
  
      $fh = fopen($namafile,"w");  
      fwrite($fh,$data);
  
      fclose($file);  
  
      echo "&lt;h2&gt;Hasil Penyimpanan Data&lt;/h2&gt;";  
      echo "&lt;hr&gt;";  
      echo "Hasil : &lt;a href='$namafile'&gt; $namafile &lt;/a&gt;";
  </code></pre>
  
  <p>I use it in my index.php with the means that I can get data from the input form directly and then save as a .txt file.</p>
  
  <p>Here's my code in the controller that's saving to my database:</p>
  
  <pre><code>public function store(Request $request)
  {
      $employee = new Employee();
      $employee-&gt;nama = $request-&gt;get('name');
      $employee-&gt;email = $request-&gt;get('email');
      $employee-&gt;dob = $request-&gt;get('date');
      $employee-&gt;phone = $request-&gt;get('phone');
      $employee-&gt;gender = $request-&gt;get('gender');
      $employee-&gt;addreess = $request-&gt;get('addreess');
      $employee-&gt;save();
  
      return redirect('employees')-&gt;with('success','Selamat, Data berhasil di tambahkan !');
  }
  </code></pre>
  
  <p>How can I save the input data to the database and at the same time how can I save the data to a text file?</p>
  
  <p>Thanks for your help. :)</p>