From c6edbf93dd369d90fd4a873286ed20ed0af0d3dc Mon Sep 17 00:00:00 2001 From: choibk Date: Sun, 7 Dec 2025 12:28:47 +0900 Subject: [PATCH] =?UTF-8?q?20.=20=EC=9E=85=EC=B6=9C=EA=B3=A0=EC=9D=B4?= =?UTF-8?q?=EB=A0=A5=20=EA=B9=8C=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/StockLogController.php | 13 ++++++- app/Models/StockLog.php | 13 +++++++ resources/views/inc/topbar.blade.php | 2 +- resources/views/stock_log/list.blade.php | 40 +++++++++++++++++++++ routes/web.php | 4 ++- 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 resources/views/stock_log/list.blade.php diff --git a/app/Http/Controllers/StockLogController.php b/app/Http/Controllers/StockLogController.php index 74e9289..c1d41c7 100644 --- a/app/Http/Controllers/StockLogController.php +++ b/app/Http/Controllers/StockLogController.php @@ -9,7 +9,18 @@ use Illuminate\Http\Request; class StockLogController extends Controller { - public function Input(Request $request, $id) + public function index(Request $request) + { + $perPage = (int) $request->input('per_page', 20); // 페이지에 표시 할 목록의 수 + $title = '입출고 이력'; + // Eager Loading 으로 N + 1 문제 해결 + $logs = StockLog::with(['product:id,name,sku']) + ->latestFirst() + ->paginate($perPage); + return view('stock_log.list',compact('title','logs')); + } + + public function input(Request $request, $id) { // queryString action 의 default value 는 in 으로 한다. $action = $request->query('action','in'); diff --git a/app/Models/StockLog.php b/app/Models/StockLog.php index 23125db..cf38307 100644 --- a/app/Models/StockLog.php +++ b/app/Models/StockLog.php @@ -8,7 +8,20 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; class StockLog extends Model { protected $table = 'stock_logs'; + protected $guarded = []; + + protected $casts = [ + 'change_amount' => 'integer', + 'created_at' => 'datetime', + 'updated_at' => 'datetime', + ]; + + public function scopeLatestFirst($qurey) + { + return $qurey->orderByDesc('created_at')->orderByDesc('id'); + } + public function product(): BelongsTo { return $this->belongsTo(Product::class); diff --git a/resources/views/inc/topbar.blade.php b/resources/views/inc/topbar.blade.php index d43ff82..7e6a7ca 100644 --- a/resources/views/inc/topbar.blade.php +++ b/resources/views/inc/topbar.blade.php @@ -14,7 +14,7 @@