php - How store create time automatically to the table when we create new ID -


in group page creating new group id, when create groupid automatically time need store database, column creationtime. using laravel 5.2 framework building application. how can take creation time , store same database when inserting groupid table. groupcontroller.php

public function groupinsert() {     $postgeozone=input::all();     //insert data mysql table     $account = account::select('accountid')->get();      foreach ($account $acc) {         $abc = $acc->accountid;     }      $data = array(         "accountid" => $abc,         "groupid"=> $postgeozone['groupid']     );      //$data=array('groupid'=> $postgeozone['groupid']);      $ck=0;     $ck=db::table('devicegroup')->insert($data);          $groups = db::table('devicegroup')->simplepaginate(5);     return view('group.groupadmin')->with('groups',$groups); } 

groupadmin.blade.php is

@extends('app')  @section('content')     <div class="templatemo-content-wrapper">         <div class="templatemo-content">             <ol class="breadcrumb">                 <li><a href="{{ url("/") }}"><font color="green">home</font></a></li>                 <li class="active">group information</li>             </ol>             <h1>view/edit group information</h1>              <p></p>              <div class="row">                 <div class="col-md-12">                     <div class="table-responsive">                          <table id="example" class="table table-striped table-hover table-bordered">                             <h3>select group :</h3>                             <thead>                             <tr>                                 <th>group id</th>                                 <th>group name</th>                                 <th>vehicle count</th>                                 <th>actions</th>                             </tr>                             </thead>                             <tbody>                             @foreach($groups $grp)                             <tr>                              <td>{{ $grp->groupid }}</td>                             <td>{{ $grp->description }}</td>                             <td></td>                                 <td>                                     <div class="btn-group">                                         <button type="button" class="btn btn-info">action</button>                                         <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">                                             <span class="caret"></span>                                             <span class="sr-only">toggle dropdown</span>                                         </button>                                         <ul class="dropdown-menu" role="menu">                                             {{--@if ($nam->isactive == 'yes')--}}                                             <li data-toggle="modal" data-target="#acceptmodal" data-bookingid="{{ $grp->groupid }}"><a href="{{ url('/group/edit/'.$grp->groupid) }}">view/ edit</a>                                             </li>                                             {{--@endif--}}                                             <li><a href="{{ url('/group/delete/'.$grp->groupid)}}">delete</a></li>                                         </ul>                                     </div>                                 </td>                             </tr>                             @endforeach                             </tbody>                         </table>                         {{$groups->links()}}                     </div>                 </div>             </div>         </div>     </div>     </br> {{--creating new group--}}     {{--------------------------------------------------}}     <h4>create new group</h4>     <form role="form" method="post" action="{{ url('groupadmin') }}">         <input type="hidden" name="_token" value="{{ csrf_token() }}">           <div class="row">             <div class="col-md-6 margin-bottom-15">                  <input type="text" class="form-control" name="groupid" value="{{ old('groupid') }}" placeholder="enter group id">             </div>             <div class="row templatemo-form-buttons">                 <div class="submit-button">                     <button type="submit" class="btn btn-primary">new</button>                  </div>             </div>         </div>     </form>           <script type="text/javascript">             $(document).ready(function() {                 $('#example').datatable();             } );         </script> @endsection 

routes.php

route::any('groupadmin', 'groupcontroller@getindex'); route::post('groupadmin', 'groupcontroller@groupinsert'); 

model group.php

 <?php  namespace app;  use illuminate\database\eloquent\model;  class group extends model {      protected $table = 'devicegroup';     /**      * attributes mass assignable.      *      * @var array      */     protected $fillable = [         'groupid', 'description',     ];      protected $hidden = [         'password', 'remember_token',     ]; } 

can please tell how , replies appreciable.

use

schema::table('devicegroup', function (blueprint $table) {              $table->timestamps();          }); 

in migration , laravel include inserted_at , updated_at , take care of updating columns when use model insert data. not need add code dates set.

also have group model, not using in controller. instead of db::table('devicegroup')->insert($data); use group::create($data); , similar getting data.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -