Skip to content

Commit

Permalink
Merge pull request #47 from Crudzaso/feature/1869/create-cruds
Browse files Browse the repository at this point in the history
Feature/1869/create cruds
  • Loading branch information
DiegoAndresRamirez authored Nov 9, 2024
2 parents dcfbf37 + 005a400 commit e93d7ed
Show file tree
Hide file tree
Showing 59 changed files with 1,791 additions and 358 deletions.
62 changes: 31 additions & 31 deletions Modules/Draws/app/Http/Controllers/DrawsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,62 @@

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Draws\Models\Draws;
use Modules\Lotery\Models\Lotery;

class DrawsController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
return view('draws::index');
$draws = Draws::with('lottery')->paginate(10);
return view('draws::index', compact('draws'));
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('draws::create');
$lotteries = Lotery::all();
return view('draws::create', compact('lotteries'));
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
$request->validate([
'lottery_id' => 'required|exists:lotteries,id',
'draw_date' => 'required|date',
'winning_numbers' => 'nullable|string',
]);

/**
* Show the specified resource.
*/
public function show($id)
{
return view('draws::show');
Draws::create($request->all());

return redirect()->route('draws.index')->with('success', 'Sorteo creado exitosamente.');
}

/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
return view('draws::edit');
$draw = Draws::findOrFail($id);
$lotteries = Lotery::all();
return view('draws::edit', compact('draw', 'lotteries'));
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
//
$request->validate([
'lottery_id' => 'required|exists:lotteries,id',
'draw_date' => 'required|date',
'winning_numbers' => 'nullable|string',
]);

$draw = Draws::findOrFail($id);
$draw->update($request->all());

return redirect()->route('draws.index')->with('success', 'Sorteo actualizado exitosamente.');
}

/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
//
$draw = Draws::findOrFail($id);
$draw->delete();

return redirect()->route('draws.index')->with('success', 'Sorteo eliminado exitosamente.');
}
}
2 changes: 2 additions & 0 deletions Modules/Draws/resources/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// resources/assets/js/app.js
import 'tailwindcss/tailwind.css';
27 changes: 27 additions & 0 deletions Modules/Draws/resources/views/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@extends('draws::layouts.master')

@section('content')
<div class="container mx-auto px-6 py-10">
<h1 class="text-3xl font-extrabold text-gray-800 mb-6">Crear Sorteo</h1>
<form action="{{ route('draws.store') }}" method="POST" class="bg-white shadow-lg rounded-lg p-6">
@csrf
<div class="mb-4">
<label class="block text-gray-700">Lotería</label>
<select name="lottery_id" class="w-full px-4 py-2 rounded-lg border">
@foreach($lotteries as $lottery)
<option value="{{ $lottery->id }}">{{ $lottery->name }}</option>
@endforeach
</select>
</div>
<div class="mb-4">
<label class="block text-gray-700">Fecha del Sorteo</label>
<input type="datetime-local" name="draw_date" class="w-full px-4 py-2 rounded-lg border">
</div>
<div class="mb-4">
<label class="block text-gray-700">Números Ganadores</label>
<input type="text" name="winning_numbers" placeholder="Ejemplo: 12, 34, 56" class="w-full px-4 py-2 rounded-lg border">
</div>
<button type="submit" class="px-6 py-2 bg-blue-600 text-white rounded-lg">Guardar</button>
</form>
</div>
@endsection
28 changes: 28 additions & 0 deletions Modules/Draws/resources/views/edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@extends('draws::layouts.master')

@section('content')
<div class="container mx-auto px-6 py-10">
<h1 class="text-3xl font-extrabold text-gray-800 mb-6">Editar Sorteo</h1>
<form action="{{ route('draws.update', $draw->id) }}" method="POST" class="bg-white shadow-lg rounded-lg p-6">
@csrf
@method('PUT')
<div class="mb-4">
<label class="block text-gray-700">Lotería</label>
<select name="lottery_id" class="w-full px-4 py-2 rounded-lg border">
@foreach($lotteries as $lottery)
<option value="{{ $lottery->id }}" {{ $draw->lottery_id == $lottery->id ? 'selected' : '' }}>{{ $lottery->name }}</option>
@endforeach
</select>
</div>
<div class="mb-4">
<label class="block text-gray-700">Fecha del Sorteo</label>
<input type="datetime-local" name="draw_date" value="{{ $draw->draw_date }}" class="w-full px-4 py-2 rounded-lg border">
</div>
<div class="mb-4">
<label class="block text-gray-700">Números Ganadores</label>
<input type="text" name="winning_numbers" value="{{ $draw->winning_numbers }}" class="w-full px-4 py-2 rounded-lg border">
</div>
<button type="submit" class="px-6 py-2 bg-blue-600 text-white rounded-lg">Actualizar</button>
</form>
</div>
@endsection
71 changes: 69 additions & 2 deletions Modules/Draws/resources/views/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,74 @@
@extends('draws::layouts.master')

@section('content')
<h1>Hello World</h1>
<div class="container mx-auto px-6 py-10">
<!-- Encabezado -->
<div class="flex justify-between items-center mb-8">
<h1 class="text-3xl font-extrabold text-gray-800">Gestión de Sorteos</h1>
<a href="{{ route('draws.create') }}" class="px-6 py-2 bg-green-600 text-white font-semibold rounded-lg shadow-md hover:bg-green-700">
Nuevo Sorteo
</a>
</div>

<p>Module: {!! config('draws.name') !!}</p>
<!-- Tabla de Sorteos -->
<div class="bg-white shadow-lg rounded-lg overflow-hidden">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-blue-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-bold text-gray-600 uppercase">Lotería</th>
<th class="px-6 py-3 text-left text-xs font-bold text-gray-600 uppercase">Fecha</th>
<th class="px-6 py-3 text-left text-xs font-bold text-gray-600 uppercase">Números Ganadores</th>
<th class="px-6 py-3 text-left text-xs font-bold text-gray-600 uppercase">Acciones</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@forelse ($draws as $draw)
<tr class="hover:bg-gray-100">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">{{ $draw->lottery->name }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">{{ $draw->draw_date }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-800">{{ $draw->winning_numbers ?? 'N/A' }}</td>
<td class="px-6 py-4 whitespace-nowrap flex gap-3">
<!-- Botón Editar -->
<a href="{{ route('draws.edit', $draw->id) }}" class="px-4 py-2 bg-yellow-500 text-white rounded-lg hover:bg-yellow-600">
Editar
</a>
<!-- Botón Eliminar -->
<form action="{{ route('draws.destroy', $draw->id) }}" method="POST" onsubmit="return confirm('¿Estás seguro de eliminar este sorteo?');">
@csrf
@method('DELETE')
<button type="submit" class="px-4 py-2 bg-red-600 text-white text-sm font-semibold rounded-lg shadow hover:bg-red-700">
Eliminar
</button>
</form>
</td>
</tr>
@empty
<tr>
<td colspan="4" class="px-6 py-4 text-center text-sm text-gray-600">No hay sorteos registrados.</td>
</tr>
@endforelse
</tbody>
</table>
</div>

<!-- Paginación -->
<div class="flex justify-between items-center mt-6">
<p class="text-sm text-gray-600">
Mostrando página {{ $draws->currentPage() }} de {{ $draws->lastPage() }}.
</p>
<div class="flex gap-2">
@if ($draws->onFirstPage())
<span class="px-4 py-2 bg-gray-300 text-gray-700 rounded-lg shadow cursor-not-allowed">Anterior</span>
@else
<a href="{{ $draws->previousPageUrl() }}" class="px-4 py-2 bg-gray-300 text-gray-700 rounded-lg shadow hover:bg-gray-400">Anterior</a>
@endif

@if ($draws->hasMorePages())
<a href="{{ $draws->nextPageUrl() }}" class="px-4 py-2 bg-gray-300 text-gray-700 rounded-lg shadow hover:bg-gray-400">Siguiente</a>
@else
<span class="px-4 py-2 bg-gray-300 text-gray-700 rounded-lg shadow cursor-not-allowed">Siguiente</span>
@endif
</div>
</div>
</div>
@endsection
9 changes: 5 additions & 4 deletions Modules/Draws/resources/views/layouts/master.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
<link rel="preconnect" href="https://fonts.bunny.net">
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />

{{-- Vite CSS --}}
{{-- {{ module_vite('build-draws', 'resources/assets/sass/app.scss') }} --}}
<!-- Vite CSS (omitido el SCSS) -->
{{-- @vite('Modules/Draws/resources/assets/sass/app.scss', 'build-draws') --}}
</head>

<body>
@yield('content')

{{-- Vite JS --}}
{{-- {{ module_vite('build-draws', 'resources/assets/js/app.js') }} --}}
<!-- Vite JS -->
@vite('Modules/Draws/resources/assets/js/app.js', 'build-draws')
</body>
</html>
20 changes: 7 additions & 13 deletions Modules/Draws/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
use Illuminate\Support\Facades\Route;
use Modules\Draws\Http\Controllers\DrawsController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::group([], function () {
Route::resource('draws', DrawsController::class)->names('draws');
Route::prefix('draws')->middleware(['auth', 'role:admin'])->name('draws.')->group(function () {
Route::get('/', [DrawsController::class, 'index'])->name('index');
Route::get('/create', [DrawsController::class, 'create'])->name('create');
Route::post('/store', [DrawsController::class, 'store'])->name('store');
Route::get('/{id}/edit', [DrawsController::class, 'edit'])->name('edit');
Route::put('/{id}', [DrawsController::class, 'update'])->name('update');
Route::delete('/{id}', [DrawsController::class, 'destroy'])->name('destroy');
});
57 changes: 27 additions & 30 deletions Modules/Lotery/app/Http/Controllers/LoteryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,59 @@

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Lotery\Models\Lotery;

class LoteryController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
return view('lotery::index');
$lotteries = Lotery::paginate(10);
return view('lotery::index', compact('lotteries'));
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('lotery::create');
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
$request->validate([
'name' => 'required|string|max:255',
'description' => 'nullable|string',
'image_url' => 'nullable|url',
]);

/**
* Show the specified resource.
*/
public function show($id)
{
return view('lotery::show');
Lotery::create($request->all());

return redirect()->route('lotery.index')->with('success', 'Lotería creada exitosamente.');
}

/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
return view('lotery::edit');
$lotery = Lotery::findOrFail($id);
return view('lotery::edit', compact('lotery'));
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
//
$request->validate([
'name' => 'required|string|max:255',
'description' => 'nullable|string',
'image_url' => 'nullable|url',
]);

$lotery = Lotery::findOrFail($id);
$lotery->update($request->all());

return redirect()->route('lotery.index')->with('success', 'Lotería actualizada exitosamente.');
}

/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
//
$lotery = Lotery::findOrFail($id);
$lotery->delete();

return redirect()->route('lotery.index')->with('success', 'Lotería eliminada exitosamente.');
}
}
1 change: 1 addition & 0 deletions Modules/Lotery/resources/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'tailwindcss/tailwind.css';
23 changes: 23 additions & 0 deletions Modules/Lotery/resources/views/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@extends('lotery::layouts.master')

@section('content')
<div class="container mx-auto px-6 py-10">
<h1 class="text-3xl font-extrabold text-gray-800 mb-6">Crear Nueva Lotería</h1>
<form action="{{ route('lotery.store') }}" method="POST" class="space-y-6">
@csrf
<div>
<label class="block text-sm font-medium text-gray-700">Nombre</label>
<input type="text" name="name" class="w-full px-4 py-2 border rounded-lg" required>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">Descripción</label>
<textarea name="description" class="w-full px-4 py-2 border rounded-lg"></textarea>
</div>
<div>
<label class="block text-sm font-medium text-gray-700">URL de la Imagen</label>
<input type="url" name="image_url" class="w-full px-4 py-2 border rounded-lg">
</div>
<button type="submit" class="px-6 py-2 bg-blue-600 text-white rounded-lg">Guardar</button>
</form>
</div>
@endsection
Loading

0 comments on commit e93d7ed

Please sign in to comment.