diff --git a/app/Http/Controllers/Admin/HistoryController.php b/app/Http/Controllers/Admin/HistoryController.php new file mode 100644 index 0000000..5205e4c --- /dev/null +++ b/app/Http/Controllers/Admin/HistoryController.php @@ -0,0 +1,93 @@ +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) + { + // + } +} diff --git a/app/Models/History.php b/app/Models/History.php new file mode 100644 index 0000000..726e720 --- /dev/null +++ b/app/Models/History.php @@ -0,0 +1,23 @@ +belongsTo(User::class, 'user_id', 'id'); + } + + public function addiction() + { + return $this->belongsTo(Addiction::class, 'addiction_id', 'id'); + } +} diff --git a/database/factories/HistoryFactory.php b/database/factories/HistoryFactory.php new file mode 100644 index 0000000..aed9622 --- /dev/null +++ b/database/factories/HistoryFactory.php @@ -0,0 +1,23 @@ + + */ +class HistoryFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition() + { + return [ + // + ]; + } +} diff --git a/database/migrations/2024_12_10_204602_create_histories_table.php b/database/migrations/2024_12_10_204602_create_histories_table.php new file mode 100644 index 0000000..0819992 --- /dev/null +++ b/database/migrations/2024_12_10_204602_create_histories_table.php @@ -0,0 +1,34 @@ +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'); + } +}; diff --git a/database/seeders/HistorySeeder.php b/database/seeders/HistorySeeder.php new file mode 100644 index 0000000..d010928 --- /dev/null +++ b/database/seeders/HistorySeeder.php @@ -0,0 +1,19 @@ + + + + + +@endsection +@section('content') +
+
+
+
+
+

History

+ +
+ +
+ +
+
+
+
+
+
+
+

History Data

+
+
+ + + + + + + + + + + + @foreach ($histories as $history) + + + + + + + + @endforeach + +
#NameAddictionResultDate Time
{{ $loop->iteration }}{{ $history->user->name }}{{ $history->addiction->name }}{{ $history->result }}{{ $history->created_at->format('d-m-Y H:i:s') }}
+
+
+
+
+
+
+@endsection +@section('scripts') + + + + + + + + +@endsection diff --git a/resources/views/layouts/sidebar.blade.php b/resources/views/layouts/sidebar.blade.php index 5b48079..f82157d 100644 --- a/resources/views/layouts/sidebar.blade.php +++ b/resources/views/layouts/sidebar.blade.php @@ -48,6 +48,12 @@ +
  • + + + Histories + +
  • diff --git a/routes/web.php b/routes/web.php index 1a4badb..ed99bd8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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 () {