title: php -laravel How to Save custom data from user input
body: <p>I want to save Registration Number data in my laravel project where </p>
  
  <pre><code>Registration Number format: &lt;dept code&gt;-&lt;current year&gt;-XXX. For example, CSE-2012-001,
  </code></pre>
  
  <p>Here dept code will come from UI side when a user select a particular department.
  How do I do it..Any idea or possible solution?</p>
  
  <p>Here is my controller:</p>
  
  <pre><code> public function saveStudent(Request $request)
      {
           $this-&gt;validate($request,[                      
              'email' =&gt; 'required|unique:students', 
              'contact_no' =&gt; 'required|regex:/(01)[0-9]{9}/',     
  
              ]);
              $student = new Student();           
              $student-&gt;name = $request-&gt;Input(['name']);       
  
              $student-&gt;email = $request-&gt;Input(['email']);
              $student-&gt;contact_no = $request-&gt;Input(['contact_no']);     
              $student-&gt;address = $request-&gt;Input(['address']);
              $student-&gt;date = $request-&gt;Input(['date']);      
              $student-&gt;department_id=$request-&gt;Input(['department_id']);
              $student-&gt;registraion_number =            
              $teacher-&gt;save();            
              return redirect('teacherSavePage'); 
      } 
  </code></pre>
  
  <p>Here is my blade View : </p>
  
  <pre><code>@extends('layouts.master')
  @section('title')
  Student Registration
  @endsection
  @section('content')
  @include('partials.message-block')
          &lt;div class="container" &gt;
              &lt;h3&gt; Student Registration &lt;/h3&gt;
          {!! Form::open(array('route' =&gt; 'saveStudent','class'=&gt;'form-horizontal','method'=&gt;'POST'))  !!}
      {!! Form::token(); !!}
      {!!   csrf_field() ; !!} 
  
              &lt;div class="form-group"&gt;
                  &lt;label&gt;Name&lt;/label&gt;
                  &lt;input type="text" name="name" class="form-control" required placeholder="Name"&gt;
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;label&gt;Email&lt;/label&gt;
                  &lt;input type="email" name="email" class="form-control" required placeholder="Email"&gt;
              &lt;/div&gt;
  
            &lt;div class="form-group"&gt;
            &lt;label&gt;Phone&lt;/label&gt;
            &lt;input type="text" name="contact_no" class="form-control" required placeholder="Phone"&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
            &lt;label&gt;Date&lt;/label&gt;
            &lt;input type="text" id="txtDate" name="date"  class="form-control" required &gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
            &lt;label&gt;Address&lt;/label&gt;          
            &lt;textarea class="form-control" name="address" required placeholder="Address" rows="3"&gt;&lt;/textarea&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;label for=""&gt;Department&lt;/label&gt;
              &lt;select class="form-control input-sm" required name="department_id" &gt;
              @foreach($department as $row)
              &lt;option value="{{$row-&gt;id}}"&gt;{{$row-&gt;name}}&lt;/option&gt;
              @endforeach
              &lt;/select&gt;
          &lt;/div&gt; 
  
              &lt;button type="submit" class="btn btn-default"&gt;Submit&lt;/button&gt;
          {!! Form::close() !!}
          &lt;/div&gt;
  
      &lt;script type="text/javascript"&gt;
      $(document).ready(function() {
                $('#txtDate').datepicker();
                $('#txtDate').datepicker('setDate', 'today');
        });
      &lt;/script&gt;
  
  @endsection
  </code></pre>