jquery - php -laravel How to Save custom data from user input -


i want save registration number data in laravel project

registration number format: <dept code>-<current year>-xxx. example, cse-2012-001, 

here dept code come ui side when user select particular department. how do it..any idea or possible solution?

here controller:

 public function savestudent(request $request)     {          $this->validate($request,[                                   'email' => 'required|unique:students',              'contact_no' => 'required|regex:/(01)[0-9]{9}/',                   ]);             $student = new student();                        $student->name = $request->input(['name']);                     $student->email = $request->input(['email']);             $student->contact_no = $request->input(['contact_no']);                  $student->address = $request->input(['address']);             $student->date = $request->input(['date']);                   $student->department_id=$request->input(['department_id']);             $student->registraion_number =                         $teacher->save();                         return redirect('teachersavepage');      }  

here blade view :

@extends('layouts.master') @section('title') student registration @endsection @section('content') @include('partials.message-block')         <div class="container" >             <h3> student registration </h3>         {!! form::open(array('route' => 'savestudent','class'=>'form-horizontal','method'=>'post'))  !!}     {!! form::token(); !!}     {!!   csrf_field() ; !!}               <div class="form-group">                 <label>name</label>                 <input type="text" name="name" class="form-control" required placeholder="name">             </div>              <div class="form-group">                 <label>email</label>                 <input type="email" name="email" class="form-control" required placeholder="email">             </div>            <div class="form-group">           <label>phone</label>           <input type="text" name="contact_no" class="form-control" required placeholder="phone">         </div>          <div class="form-group">           <label>date</label>           <input type="text" id="txtdate" name="date"  class="form-control" required >         </div>          <div class="form-group">           <label>address</label>                     <textarea class="form-control" name="address" required placeholder="address" rows="3"></textarea>         </div>          <div class="form-group">             <label for="">department</label>             <select class="form-control input-sm" required name="department_id" >             @foreach($department $row)             <option value="{{$row->id}}">{{$row->name}}</option>             @endforeach             </select>         </div>               <button type="submit" class="btn btn-default">submit</button>         {!! form::close() !!}         </div>      <script type="text/javascript">     $(document).ready(function() {               $('#txtdate').datepicker();               $('#txtdate').datepicker('setdate', 'today');       });     </script>  @endsection 

if understood correctly, should this:

$currentid = student::orderby('id', 'desc')->first()->id + 1;  $student->registraion_number = $student->department_id.'-'.date("y").'-'.$currentid; 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -