Files
dockersyshome/app/Http/Controllers/Admin/DownloadController.php
T
marco 38295e7e88 feat(cms): implement complete SysSiteCMS content management system
Initial implementation of the HomeSysPanel CMS built with Laravel 13.0.
Includes complete admin panel, content management, user authentication,
modular architecture for products/services/chatbot, and marketing tools.

Key features:
- User authentication with email verification and password reset
- Role-based access control (Admin/User with granular permissions)
- Content management (pages, news, FAQ, downloads, galleries, banners)
- Contact management system with subjects and responses
- Marketing tools (email campaigns, visitor analytics, social sharing)
- Modular architecture (Products, Services, Chatbot modules)
- AI Chatbot integration with OpenRouter.ai and LlamaCpp support
- Visitor tracking with geolocation
- SEO optimization with meta tags and Open Graph
- Responsive design with Bootstrap 5
- Dark mode support
- Maintenance mode
- Feature request system
2026-09-07 19:06:53 -03:00

89 lines
2.9 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Download;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class DownloadController extends Controller
{
public function index()
{
$downloads = Download::latest()->paginate(10);
return view('admin.downloads.index', compact('downloads'));
}
public function create()
{
return view('admin.downloads.create');
}
public function store(Request $request)
{
$request->validate([
'title' => 'required|string|max:255',
'description' => 'nullable|string',
'file' => 'required|file|max:20480|mimes:pdf,doc,docx,zip,rar,txt,xls,xlsx', // Máx 20MB
'file_type' => 'required|string|in:Driver,Manual,Software,Outro',
], [
'file.mimes' => 'O arquivo deve ser do tipo: PDF, DOC, DOCX, ZIP, RAR, TXT, XLS ou XLSX.',
]);
$path = $request->file('file')->store('downloads', 'public');
Download::create([
'title' => $request->title,
'description' => $request->description,
'file_path' => $path,
'file_type' => $request->file_type,
'active' => true,
]);
return redirect()->route('admin.downloads.index')->with('success', 'Download cadastrado com sucesso.');
}
public function edit(Download $download)
{
return view('admin.downloads.edit', compact('download'));
}
public function update(Request $request, Download $download)
{
$request->validate([
'title' => 'required|string|max:255',
'description' => 'nullable|string',
'file' => 'nullable|file|max:20480|mimes:pdf,doc,docx,zip,rar,txt,xls,xlsx',
'file_type' => 'required|string|in:Driver,Manual,Software,Outro',
'active' => 'required|boolean',
], [
'file.mimes' => 'O arquivo deve ser do tipo: PDF, DOC, DOCX, ZIP, RAR, TXT, XLS ou XLSX.',
]);
$data = [
'title' => $request->title,
'description' => $request->description,
'file_type' => $request->file_type,
'active' => $request->active,
];
if ($request->hasFile('file')) {
// Remove o arquivo antigo
Storage::disk('public')->delete($download->file_path);
$data['file_path'] = $request->file('file')->store('downloads', 'public');
}
$download->update($data);
return redirect()->route('admin.downloads.index')->with('success', 'Download atualizado com sucesso.');
}
public function destroy(Download $download)
{
Storage::disk('public')->delete($download->file_path);
$download->delete();
return redirect()->route('admin.downloads.index')->with('success', 'Download excluído com sucesso.');
}
}