- Exports ProductReportExport ----------------------------------------------------------------------------------------
IT9
- maatwebsite/excel for Excel exports.
composer require maatwebsite/excel
php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" --tag=config
- App/Models
Product ---------------------------------------------------
- resources/views/products create.blade------------------------------------------------------------------------------------------------------------------- @extends('layouts.app')
@section('content')
<div class="bg-white rounded shadow p-6">
<form method="POST" action="{{ route('products.store') }}">
@csrf
{{-- Name --}}
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 mb-1">Name *</label>
<input type="text" name="name" value="{{ old('name') }}"
class="w-full border rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400 @error('name') border-red-400 @enderror">
@error('name') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
</div>
{{-- Category --}}
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 mb-1">Category</label>
<input type="text" name="category" value="{{ old('category') }}"
class="w-full border rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400">
</div>
{{-- Price & Quantity side by side --}}
<div class="flex gap-4 mb-4">
<div class="flex-1">
<label class="block text-sm font-medium text-gray-700 mb-1">Price *</label>
<input type="number" name="price" value="{{ old('price') }}" step="0.01" min="0"
class="w-full border rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400 @error('price') border-red-400 @enderror">
@error('price') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
</div>
<div class="flex-1">
<label class="block text-sm font-medium text-gray-700 mb-1">Quantity *</label>
<input type="number" name="quantity" value="{{ old('quantity', 0) }}" min="0"
class="w-full border rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400 @error('quantity') border-red-400 @enderror">
@error('quantity') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
</div>
</div>
{{-- Description --}}
<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 mb-1">Description</label>
<textarea name="description" rows="3"
class="w-full border rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400">{{ old('description') }}</textarea>
</div>
<div class="flex gap-3">
<button type="submit"
class="bg-blue-600 text-white px-5 py-2 rounded hover:bg-blue-700 text-sm">
Save Product
</button>
<a href="{{ route('products.index') }}"
class="px-5 py-2 rounded border text-sm text-gray-600 hover:bg-gray-50">
Cancel
</a>
</div>
</form>
</div>
@endsection edit.blade------------------------------------------------------------------------------------------------------------------- @extends('layouts.app')
@section('content')
<div class="bg-white rounded shadow p-6">
<form method="POST" action="{{ route('products.update', $product) }}">
@csrf @method('PUT')
{{-- Name --}}
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 mb-1">Name *</label>
<input type="text" name="name" value="{{ old('name', $product->name) }}"
class="w-full border rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400 @error('name') border-red-400 @enderror">
@error('name') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
</div>
{{-- Category --}}
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700 mb-1">Category</label>
<input type="text" name="category" value="{{ old('category', $product->category) }}"
class="w-full border rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400">
</div>
{{-- Price & Quantity --}}
<div class="flex gap-4 mb-4">
<div class="flex-1">
<label class="block text-sm font-medium text-gray-700 mb-1">Price *</label>
<input type="number" name="price" value="{{ old('price', $product->price) }}" step="0.01" min="0"
class="w-full border rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400 @error('price') border-red-400 @enderror">
@error('price') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
</div>
<div class="flex-1">
<label class="block text-sm font-medium text-gray-700 mb-1">Quantity *</label>
<input type="number" name="quantity" value="{{ old('quantity', $product->quantity) }}" min="0"
class="w-full border rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400 @error('quantity') border-red-400 @enderror">
@error('quantity') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
</div>
</div>
{{-- Description --}}
<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 mb-1">Description</label>
<textarea name="description" rows="3"
class="w-full border rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-400">{{ old('description', $product->description) }}</textarea>
</div>
<div class="flex gap-3">
<button type="submit"
class="bg-blue-600 text-white px-5 py-2 rounded hover:bg-blue-700 text-sm">
Update Product
</button>
<a href="{{ route('products.index') }}"
class="px-5 py-2 rounded border text-sm text-gray-600 hover:bg-gray-50">
Cancel
</a>
</div>
</form>
</div>
@endsection index.blade------------------------------------------------------------------------------------------------------------------- @extends('layouts.app')
@section('content')
{{-- Flash Messages --}} @if(session('success')) {{ session('success') }} @endif
{{-- Table --}}
{{-- Pagination --}}
-
resources/views dashboard------------------------------------------------------------------------------------------------------------------- {{ __('Dashboard') }}
reports.blade------------------------------------------------------------------------------------------------------------
@extends('layouts.app')
@section('content')
{{-- Summary Cards --}}
{{-- By Category --}}
{{-- Full Product List --}}
- web.php------------------------------------------------------------------------------------------------------------------
Question?
Do we have to guess your question ?
Is this a how to use maatwebsite/excel article?
Please or to participate in this conversation.