sufrí un rato por un error que lanzaba, hasta que recordé y me di cuenta que para poder acceder a esta ruta debo de estar logeado.
Introducción a Laravel
Introducción a Laravel 9: Configuración Inicial y Bienvenida
Estructura principal de Laravel
Fundamentos de Laravel
Uso de Artisan en Laravel: Comandos y Funciones
Manejo de Solicitudes HTTP en PHP
Uso de Blade para Crear Vistas en Laravel
Configuración de Plantillas para Vistas Reutilizables en Laravel
Controladores en Laravel: Gestión de Rutas y Peticiones
Cómo Crear Migraciones en Laravel
Cómo Crear Modelos en Laravel
Manejo de Datos con Eloquent en Laravel
Configuración de Relaciones entre Tablas con Eloquent
Manos a la obra con nuestro proyecto
Enfoque del proyecto
Inicio de sesión
Sistema de inicio de sesión
Panel administrativo
Listado de publicaciones
Función de eliminar
Crear y editar (primer paso)
Controles de un formulario
Función de guardar
Función de editar
Validación
Registros duplicados
Trabajemos en el diseño web de nuestro proyecto
Diseño web
Diseño personalizado
Página home
Destacado
Publicación individual
Buscador
Optimización
Cierre
Mejoras Finales y Cierre del Proyecto en Laravel
You don't have access to this class
Keep learning! Join and start boosting your career
The initial configuration of an administrative panel is crucial to ensure a smooth and organized development environment. In this lesson, we will focus on configuring the routes needed to manage a publishing table within a Laravel project. The main focus will be on how to properly structure and manage routes to maximize their functionality and efficiency.
To start, we need to import the controller we will use. We use resource
type routes, which allow us to handle CRUD actions (Create, Read, Update, Delete) in a systematic way. We start by defining the routes for our posts using the postsController
class.
// Defining the resource routeRoute::resource('posts', PostController::class)->except(['show']);
In this case, we indicate that we will work with all routes except the show
route.
To verify that our routes are configured correctly, we can use the Artisan command to list all the routes defined within our project:
php artisan route:list
This command will display a list of routes, allowing us to see the GET
, POST
, PUT
and DELETE
routes we have configured. Each one has a specific function:
Once the routes are configured, we must implement the necessary logic in the controller. We start by creating the index
method, which will be responsible for returning a specific view. This method is essential to display the list of publications.
public function index() { return view('posts.index');}
This code returns a view that will be stored in a specific folder of our project, which has not been created yet.
To display the publications, we need to create a new folder and file inside our project's view directory. This will be responsible for presenting the data visually to the user.
Navigate to resources/views
.
We create a new folder called posts
.
Inside this folder, we add an index.blade.php
file.
Here we will use an administrative template, such as DASHBOARD
, to structure our page. We simply copy the base structure, paste it into our new file and make the necessary modifications:
@extends('layouts.dashboard')
@section('content') <h1>Listof posts</h1><!-- HTML code could be included here to display the posts-->@endsection.
Once everything is configured, we can check in the browser. Navigating to the path configured for INDEX
, we should see the list of posts. If when refreshing a message appears that the view does not exist, let's make sure that everything is correctly configured. After the correct creation of files and paths, the system should be functional, taking advantage of the administrative panel template to manage publications efficiently.
This type of configuration is essential to work with administrative panels and take full advantage of the functionalities that Laravel offers to manage dynamic content in an organized and efficient way.
Contributions 12
Questions 4
sufrí un rato por un error que lanzaba, hasta que recordé y me di cuenta que para poder acceder a esta ruta debo de estar logeado.
:’) Me está gustando cada vez más Laravel 😁
Proteger rutas en laravel
Proteger rutas siginifica envolverlas dentro de una capa de seguridad, para que solo las puedan acceder usuarios logeados.
Hay dos formas:
.
Desde el archivo de rutas:
Route::get('/dashboard', function () {
return 'esto es un closure que hace algo';
})->middleware(['auth', 'verified']);
Directamente desde el controlador (ejemplo: PostController):
// Esto es para proteger la ruta
public function __construct()
{
$this->middleware(['auth', 'verified']);
}
En ambos casos podemos podemos agregar esta opcion si no queremos proteger todos los end points de la ruta (ejeplo: en el caso de los controladores de recursos (7 rutas) o los controladores para rutas de api (5 rutas))
$this->middleware(['auth', 'verified'])->except(['index', 'show']);
Excelente forma de explicar la de profe.
Para los que tienen problemas con Post y no logra ver en la lista la ruta de post deben escribir los siguientes comandos en la consola debes limpiar la cache con este comando.
php artisan route:cache
php artisan route:list
php artisan serve
si a alguien le sale que no tiene el archivo manifest.json y por eso no funciona puede ejecutar el comando npm run build y se le soluciona el error
php artisan route:list --name=posts
Routes: Route:resource acepta todas las rutas y podemos poner ->except['show'] al final para excluir una ruta en especifico.
Want to see more contributions, questions and answers from the community?