creo que por ahora voy bien
This commit is contained in:
@@ -16,9 +16,9 @@ class RecetaController extends Controller
|
||||
public function index(): View
|
||||
{
|
||||
//return view('receta.index');
|
||||
return view('receta.index', [
|
||||
'recetas' => Receta::with('user')->latest()->get(),
|
||||
]);
|
||||
return view("receta.index", [
|
||||
"recetas" => Receta::with("user")->latest()->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,12 +35,13 @@ class RecetaController extends Controller
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'message' => 'required|string|max:255',
|
||||
"message" => "required|string|max:255",
|
||||
"title" => "required|string|max:50",
|
||||
]);
|
||||
|
||||
|
||||
$request->user()->recetas()->create($validated);
|
||||
|
||||
return redirect(route('recetas.index'));
|
||||
return redirect(route("recetas.index"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,9 +57,9 @@ class RecetaController extends Controller
|
||||
*/
|
||||
public function edit(Receta $receta): View
|
||||
{
|
||||
Gate::authorize('update', $receta);
|
||||
return view('receta.edit', [
|
||||
'receta' => $receta,
|
||||
Gate::authorize("update", $receta);
|
||||
return view("receta.edit", [
|
||||
"receta" => $receta,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -67,15 +68,16 @@ class RecetaController extends Controller
|
||||
*/
|
||||
public function update(Request $request, Receta $receta): RedirectResponse
|
||||
{
|
||||
Gate::authorize('update', $receta);
|
||||
|
||||
Gate::authorize("update", $receta);
|
||||
|
||||
$validated = $request->validate([
|
||||
'message' => 'required|string|max:255',
|
||||
"message" => "required|string|max:255",
|
||||
"title" => "required|string|max:50",
|
||||
]);
|
||||
|
||||
$receta->update($validated);
|
||||
|
||||
return redirect(route('recetas.index'));
|
||||
return redirect(route("recetas.index"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,8 +85,8 @@ class RecetaController extends Controller
|
||||
*/
|
||||
public function destroy(Receta $receta): RedirectResponse
|
||||
{
|
||||
Gate::authorize('delete', $receta);
|
||||
Gate::authorize("delete", $receta);
|
||||
$receta->delete();
|
||||
return redirect(route('recetas.index'));
|
||||
return redirect(route("recetas.index"));
|
||||
}
|
||||
}
|
||||
|
||||
25
app/Http/Controllers/RecetasPublicasController.php
Normal file
25
app/Http/Controllers/RecetasPublicasController.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Receta;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class RecetasPublicasController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$recetas = DB::table("recetas")
|
||||
->orderBy("updated_at", "desc")
|
||||
->paginate(5);
|
||||
return view("partials.recetas_lista", compact("recetas"));
|
||||
}
|
||||
|
||||
public function mostrarPaginado(int $pag): View
|
||||
{
|
||||
$recetas = Receta::Paginate(5);
|
||||
return view("recetero.index", compact("recetas"));
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,5 @@ class Receta extends Model
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
protected $fillable = [
|
||||
'message',
|
||||
];
|
||||
protected $fillable = ["message", "title"];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table("recetas", function (Blueprint $table) {
|
||||
$table->string("title")->default("[falta titulo]")->after("id");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table("recetas", function (Blueprint $table) {
|
||||
$table->dropColumn("title");
|
||||
});
|
||||
}
|
||||
};
|
||||
9
resources/views/about.blade.php
Normal file
9
resources/views/about.blade.php
Normal file
@@ -0,0 +1,9 @@
|
||||
@extends('layouts.public')
|
||||
@section('content')
|
||||
<section class="mb-8">
|
||||
<h2 class="text-2xl font-semibold mb-4">Sobre Este Proyecto</h2>
|
||||
<p class="font-medium">Este es un proyecto simple tipo crud de un recetero que muestre titulo de recetas y su preparacion.
|
||||
<br>Tambien tengo una landing page con paginacion y un buscador.
|
||||
</p>
|
||||
</section>
|
||||
@endsection
|
||||
@@ -19,6 +19,10 @@
|
||||
<x-nav-link :href="route('recetas.index')" :active="request()->routeIs('recetas.index')">
|
||||
{{ __('Recetas') }}
|
||||
</x-nav-link>
|
||||
|
||||
<x-nav-link :href="url('/')" :active="request()->routeIs('/')">
|
||||
{{__("Menu Principal")}}
|
||||
</x-nav-link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -78,6 +82,10 @@
|
||||
<x-responsive-nav-link :href="route('recetas.index')" :active="request()->routeIs('recetas.index')">
|
||||
{{ __('Recetas') }}
|
||||
</x-responsive-nav-link>
|
||||
|
||||
<x-responsive-nav-link :href="url('/')" :active="request()->routeIs('/')">
|
||||
{{__("Menu Principal")}}
|
||||
</x-responsive-nav-link>
|
||||
</div>
|
||||
|
||||
<!-- Responsive Settings Options -->
|
||||
|
||||
46
resources/views/layouts/public.blade.php
Normal file
46
resources/views/layouts/public.blade.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>@yield('title', 'Recetario')</title>
|
||||
<script src="https://unpkg.com/htmx.org@2.0.4" integrity="sha384-HGfztofotfshcF7+8n44JQL2oJmowVChPTg48S+jvZoztPfvwD79OC/LTtG6dMp+" crossorigin="anonymous"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body class="bg-gray-100">
|
||||
|
||||
<!-- Header -->
|
||||
<header class="bg-green-600 text-white p-6">
|
||||
<h1 class="text-3xl font-bold">Recetario Fede</h1>
|
||||
<nav class="mt-4">
|
||||
<ul class="flex space-x-4">
|
||||
<li><a href="/" class="hover:underline">Inicio</a></li>
|
||||
<li><a href="/recetero/0" class="hover:underline">Recetas</a></li>
|
||||
<li><a href="/about" class="hover:underline">Sobre el Proyecto</a></li>
|
||||
|
||||
@if (Route::has('login'))
|
||||
@auth
|
||||
<li><a href="{{ url('/dashboard') }}">Dashboard</a></li>
|
||||
@else
|
||||
<li><a href="{{ route('login') }}">Log in</a></li>
|
||||
@if (Route::has('register'))
|
||||
<li><a href="{{ route('register') }}">Register</a></li>
|
||||
@endif
|
||||
@endauth
|
||||
@endif
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<!-- Main Content -->
|
||||
<main class="p-6">
|
||||
@yield('content')
|
||||
</main>
|
||||
|
||||
<!-- Footer -->
|
||||
<footer class="bg-gray-800 text-white p-4 text-center">
|
||||
<p>© {{ date('Y') }} Recetario Fede</p>
|
||||
</footer>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
14
resources/views/partials/recetas_lista.blade.php
Normal file
14
resources/views/partials/recetas_lista.blade.php
Normal file
@@ -0,0 +1,14 @@
|
||||
@php
|
||||
use Illuminate\Support\Str;
|
||||
@endphp
|
||||
|
||||
@foreach ($recetas as $receta)
|
||||
<div class="bg-white m-2 p-4 rounded-lg shadow">
|
||||
|
||||
<h3 class="text-xl font-semibold mb-2">{{ $receta->title }}</h3>
|
||||
<p class="text-gray-600 mb-4">{{ Str::limit($receta->message, 20, "...") }}</p>
|
||||
<div class="flex justify-between items-center">
|
||||
<span class="text-sm text-gray-500">Ultima Vez Actualizado: {{ $receta->updated_at }} </span>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
@@ -3,14 +3,17 @@
|
||||
<form method="POST" action="{{ route('recetas.update', $receta) }}">
|
||||
@csrf
|
||||
@method('patch')
|
||||
<textarea name="title" placeholder = "{{__('titulo')}}"
|
||||
class="block w-full border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm"
|
||||
>{{old('title', $receta->title)}}</textarea>
|
||||
<textarea
|
||||
name="message"
|
||||
class="block w-full border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm"
|
||||
class="block mt-4 w-full border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm"
|
||||
>{{ old('message', $receta->message) }}</textarea>
|
||||
<x-input-error :messages="$errors->get('message')" class="mt-2" />
|
||||
<div class="mt-4 space-x-2">
|
||||
<x-primary-button>{{ __('Guardar') }}</x-primary-button>
|
||||
<x-secondary-button onclick="window.location.href='{{ route('recetas.index') }}'">{{ __('Cancelar') }}</x-secondary-button>
|
||||
<x-secondary-button onclick="window.location.href='{{ route('recetas.index') }}';">{{ __('Cancelar') }}</x-secondary-button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
<x-app-layout>
|
||||
<div>
|
||||
<div class="basis-0 ms-16 mt-2 me-16 justify-center">
|
||||
<form method="POST" action="{{ route('recetas.store')}}">
|
||||
@csrf
|
||||
<textarea name="title" placeholder = "{{__('titulo')}}"
|
||||
class="block w-full border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm"
|
||||
>{{old('title')}}</textarea>
|
||||
<textarea name="message" placeholder ="{{ __('escriba aquí')}}"
|
||||
class="block w-full border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm"
|
||||
class="mt-2 block w-full border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm"
|
||||
>{{old('message')}}</textarea>
|
||||
<x-input-error :messages="$errors->get('message')" class="mt-2" />
|
||||
<x-primary-button class="mt-4">{{ __('Publicar Receta') }}</x-primary-button>
|
||||
</form>
|
||||
<div class="mt-6 bg-white shadow-sm rounded-lg divide-y">
|
||||
<hr class="mt-4">
|
||||
<div class="mt-4 bg-white shadow-sm rounded-lg divide-y">
|
||||
@foreach ($recetas as $receta)
|
||||
<div class="p-6 flex space-x-2">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-gray-600 -scale-x-100" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" />
|
||||
</svg>
|
||||
|
||||
|
||||
<div class="flex-1">
|
||||
<div class="flex justify-between items-center">
|
||||
<div>
|
||||
@@ -49,7 +53,8 @@
|
||||
</x-dropdown>
|
||||
@endif
|
||||
</div>
|
||||
<p class="mt-4 text-lg text-gray-900">{{ $receta->message }}</p>
|
||||
<p class="mt-3 text-lg text-gray-500">{{$receta->title}}</p>
|
||||
<p class="mt-2 text-lg text-gray-900">{{ $receta->message }}</p>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
19
resources/views/recetero/index.blade.php
Normal file
19
resources/views/recetero/index.blade.php
Normal file
@@ -0,0 +1,19 @@
|
||||
@extends('layouts.public')
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<h1 class="text-2xl font-semibold mb-4">Listado de Recetas</h1>
|
||||
<div class="flex flex-col">
|
||||
@foreach ($recetas as $receta)
|
||||
<div class="bg-white p-6 rounded-lg shadow-lg mb-6">
|
||||
<h2 class="text-2xl font-bold text-gray-800">{{ $receta->title }}</h2>
|
||||
<p class="mt-4 text-gray-600">{{ $receta->message }}</p>
|
||||
<span class="text-sm text-gray-500">Ultima Vez Actualizado: {{ $receta->updated_at }} </span>
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Paginación -->
|
||||
{{ $recetas->links() }}
|
||||
</div>
|
||||
@endsection
|
||||
@@ -1,62 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Recetario</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body class="bg-gray-100 h-screen ">
|
||||
<div class="flex flex-col h-fit">
|
||||
<header class="bg-green-600 text-white p-6">
|
||||
<h1 class="text-3xl font-bold">Recetario Fede</h1>
|
||||
<nav class="mt-4">
|
||||
<ul class="flex space-x-4">
|
||||
<li><a href="#" class="hover:underline">Inicio</a></li>
|
||||
<li><a href="#" class="hover:underline">Recetas</a></li>
|
||||
<li><a href="#" class="hover:underline">Sobre Nosotros</a></li>
|
||||
<li><a href="#" class="hover:underline">Contacto</a></li>
|
||||
@if (Route::has('login'))
|
||||
@auth
|
||||
<li>
|
||||
<a
|
||||
href="{{ url('/dashboard') }}"
|
||||
>
|
||||
Dashboard
|
||||
</a></li>
|
||||
@else
|
||||
<li><a
|
||||
href="{{ route('login') }}"
|
||||
>
|
||||
Log in
|
||||
</a></li>
|
||||
|
||||
@if (Route::has('register'))
|
||||
<li><a
|
||||
href="{{ route('register') }}"
|
||||
>
|
||||
Register
|
||||
</a></li>
|
||||
@endif
|
||||
@endauth
|
||||
@endif
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
</div>
|
||||
|
||||
<main class="p-6 flex-1 overflow-auto">
|
||||
<section class="mb-8">
|
||||
<h2 class="text-2xl font-semibold mb-4">Recetas Destacadas</h2>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
<div class="bg-white p-4 rounded-lg shadow">
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer class="bg-gray-800 text-white p-4 text-center">
|
||||
<p>© 2025 Recetario Fede</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@extends('layouts.public')
|
||||
@section('content')
|
||||
<section class="mb-8">
|
||||
<h2 class="text-2xl font-semibold mb-4">Recetas Destacadas</h2>
|
||||
<div class="flex flex-grow" hx-get={{route('recetaspublicas.index', [], false) }} hx-trigger='load' hx-targer="innerHTML">Cargando ...</div>
|
||||
</section>
|
||||
@endsection
|
||||
|
||||
@@ -3,25 +3,46 @@
|
||||
use App\Http\Controllers\ProfileController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
|
||||
use App\Http\Controllers\RecetaController;
|
||||
use App\Http\Controllers\RecetasPublicasController;
|
||||
|
||||
Route::get('/', function () {
|
||||
return view('welcome');
|
||||
Route::get("/", function () {
|
||||
return view("welcome");
|
||||
});
|
||||
|
||||
Route::get('/dashboard', function () {
|
||||
return view('dashboard');
|
||||
})->middleware(['auth', 'verified'])->name('dashboard');
|
||||
|
||||
Route::middleware('auth')->group(function () {
|
||||
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
|
||||
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
|
||||
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
|
||||
Route::get("/about", function () {
|
||||
return view("about");
|
||||
});
|
||||
|
||||
Route::resource('recetas', RecetaController::class)
|
||||
->only(['index', 'store', 'edit', 'update', 'destroy'])
|
||||
->middleware(['auth', 'verified']);
|
||||
Route::get("/recetero/{pagina}", [
|
||||
RecetasPublicasController::class,
|
||||
"mostrarPaginado",
|
||||
]);
|
||||
|
||||
require __DIR__.'/auth.php';
|
||||
Route::get("/dashboard", function () {
|
||||
return view("dashboard");
|
||||
})
|
||||
->middleware(["auth", "verified"])
|
||||
->name("dashboard");
|
||||
|
||||
Route::middleware("auth")->group(function () {
|
||||
Route::get("/profile", [ProfileController::class, "edit"])->name(
|
||||
"profile.edit"
|
||||
);
|
||||
Route::patch("/profile", [ProfileController::class, "update"])->name(
|
||||
"profile.update"
|
||||
);
|
||||
Route::delete("/profile", [ProfileController::class, "destroy"])->name(
|
||||
"profile.destroy"
|
||||
);
|
||||
});
|
||||
|
||||
Route::resource("recetas", RecetaController::class)
|
||||
->only(["index", "store", "edit", "update", "destroy"])
|
||||
->middleware(["auth", "verified"]);
|
||||
|
||||
Route::resource("recetaspublicas", RecetasPublicasController::class)->only([
|
||||
"index",
|
||||
]);
|
||||
|
||||
require __DIR__ . "/auth.php";
|
||||
|
||||
Reference in New Issue
Block a user