In meiner Gruppenseite ich neue Gruppen-ID erstellen, wenn ich die Gruppennummer automatisch erstellen, die Zeit in Datenbank speichern, Spalte creationTime. Ich benutze Laravel 5.2 Framework zum Erstellen meiner Anwendung. Wie kann ich diese Erstellungszeit nehmen und diese in die Datenbank speichern, wenn ich groupID in die Tabelle einfüge? meine GroupController.phpWie Speicher erstellen Zeit automatisch auf die Tabelle, wenn wir neue ID erstellen
public function groupInsert()
{
$postGeozone=Input::all();
//insert data into mysql table
$account = Account::select('accountID')->get();
foreach ($account as $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 ist
@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 a Group :</h3>
<thead>
<tr>
<th>Group ID</th>
<th>Group Name</th>
<th>Vehicle Count</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($groups as $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">
{{[email protected] ($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>
{{[email protected]}}
<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 a 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', '[email protected]');
Route::post('groupAdmin', '[email protected]');
Modell Group.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Group extends Model
{
protected $table = 'devicegroup';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'groupID', 'description',
];
protected $hidden = [
'password', 'remember_token',
];
}
Kann jemand bitte sagen Sie wie macht man , Antworten sind spürbar.
Wie ändert man den Namen des Feldes von create_at in creationTime? –
Das Modell, das Sie erweitern, haben 'const CREATED_AT = 'created_at';', Sie könnten versuchen, es dort zu ändern. Oder wenn Sie die Kontrolle über die Datenbank haben, können Sie den Zeitstempel verwenden, um die Datenbank dazu zu bringen, die Spalte zu aktualisieren, statt sie mit laravel zu verwenden. Https://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html – rypskar
es nimmt nur Jahr .. wie kann ich Monat Tag und Zeit hinzufügen? –