This commit is contained in:
misbahsurur 2024-12-10 20:56:17 +07:00
parent c0f79f9e9e
commit 16ee9873b8
8 changed files with 278 additions and 0 deletions

View File

@ -0,0 +1,93 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\History;
use Illuminate\Http\Request;
class HistoryController extends Controller
{
public function __construct()
{
$this->middleware('role:admin');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$histories = History::with('user', 'addiction')
->orderBy('created_at', 'desc')
->get();
return view('admin.histories.index', compact('histories'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Models\History $history
* @return \Illuminate\Http\Response
*/
public function show(History $history)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\History $history
* @return \Illuminate\Http\Response
*/
public function edit(History $history)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\History $history
* @return \Illuminate\Http\Response
*/
public function update(Request $request, History $history)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\History $history
* @return \Illuminate\Http\Response
*/
public function destroy(History $history)
{
//
}
}

23
app/Models/History.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class History extends Model
{
use HasFactory;
protected $guarded = [];
public function user()
{
return $this->belongsTo(User::class, 'user_id', 'id');
}
public function addiction()
{
return $this->belongsTo(Addiction::class, 'addiction_id', 'id');
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\History>
*/
class HistoryFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
//
];
}
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('histories', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->foreignId('addiction_id')->constrained()->onDelete('cascade');
$table->decimal('result');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('histories');
}
};

View File

@ -0,0 +1,19 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class HistorySeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//
}
}

View File

@ -0,0 +1,77 @@
@extends('layouts.master')
@section('title', 'Histories Datas')
@section('styles')
<!-- DataTables -->
<link href="{{ asset('assets/libs/datatables.net-bs5/css/dataTables.bootstrap5.min.css') }}" rel="stylesheet" type="text/css" />
<!-- Responsive datatable examples -->
<link href="{{ asset('assets/libs/datatables.net-responsive-bs5/css/responsive.bootstrap5.min.css') }}" rel="stylesheet" type="text/css" />
@endsection
@section('content')
<div class="page-content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="page-title-box d-flex align-items-center justify-content-between">
<h4 class="mb-sm-0">History</h4>
<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item"><a href="javascript: void(0);">Master</a></li>
<li class="breadcrumb-item active">History</li>
</ol>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">History Data</h4>
</div>
<div class="card-body">
<table id="datatable" class="table table-hover align-middle table-bordered dt-responsive nowrap" style="border-collapse: collapse; border-spacing: 0; width: 100%;">
<thead>
<tr>
<th width="10px" class="text-center">#</th>
<th>Name</th>
<th>Addiction</th>
<th>Result</th>
<th>Date Time</th>
</tr>
</thead>
<tbody>
@foreach ($histories as $history)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $history->user->name }}</td>
<td>{{ $history->addiction->name }}</td>
<td>{{ $history->result }}</td>
<td>{{ $history->created_at->format('d-m-Y H:i:s') }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div> <!-- end col -->
</div>
</div>
</div>
@endsection
@section('scripts')
<!-- Required datatable js -->
<script src="{{ asset('assets/libs/datatables.net/js/jquery.dataTables.min.js') }}"></script>
<script src="{{ asset('assets/libs/datatables.net-bs5/js/dataTables.bootstrap5.min.js') }}"></script>
<!-- Responsive examples -->
<script src="{{ asset('assets/libs/datatables.net-responsive/js/dataTables.responsive.min.js') }}"></script>
<script src="{{ asset('assets/libs/datatables.net-responsive-bs5/js/responsive.bootstrap5.min.js') }}"></script>
<script>
$(function () {
$('#datatable').DataTable();
});
</script>
@endsection

View File

@ -48,6 +48,12 @@
</li>
</ul>
</li>
<li>
<a href="{{ route('admin.histories.index') }}" class="@if (Request::is('admin/histories*')) active @endif">
<i class="fas fa-history"></i>
<span>Histories</span>
</a>
</li>
</ul>
</div>
<!-- Sidebar -->

View File

@ -41,6 +41,9 @@
// Item
Route::resource('items', App\Http\Controllers\Admin\ItemController::class);
// History
Route::resource('histories', App\Http\Controllers\Admin\HistoryController::class);
});
Route::middleware('role:user')->name('user.')->group(function () {