You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesión a prueba de IA

Antes: $249

Currency
$209
Suscríbete

Termina en:

0 Días
4 Hrs
54 Min
38 Seg
Curso de Introducción a Laravel 9

Curso de Introducción a Laravel 9

Profesor Italo Morales F

Profesor Italo Morales F

Panel administrativo

15/31
Resources

How to configure the paths for the administrative panel?

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.

How do we start with the development of a route?

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.

What commands do we execute to list the routes?

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:

  • GET: Query or display forms.
  • POST: Send data for its creation.
  • PUT: Update existing data.
  • DELETE: Delete data.

How do we implement the controller logic?

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.

How to create the view to display the posts?

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.

  1. Navigate to resources/views.

  2. We create a new folder called posts.

  3. 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.

How do we verify that everything is working correctly?

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

Sort by:

Want to see more contributions, questions and answers from the community?

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

Listar rutas filtrando por nombre

php artisan route:list --name=posts
Hice todo como indica el profesor, pero cuando entro a la vista posts. me sale todo en blanco. ![](https://static.platzi.com/media/user_upload/image-c3e27963-3ddd-4f58-a51a-16c4c26a926c.jpg)
Alguien me puede ayudar, por que me sale este mensaje? ![](https://static.platzi.com/media/user_upload/image-694441af-2e7a-4825-ab68-37972733003e.jpg) En mi web.php tengo todo esto: ```js group(function (){ Route::get('/','home')->name('home'); Route::get('blog','blog')->name('blog'); Route::get('blog/{post:slug}', 'post')->name('post'); }); Route::resource('posts',PostController::class)->except('show'); 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'); }); require __DIR__.'/auth.php'; ```
Cree las rutas que comenta el profesor Italo pero al momento de actualiza la pagina /posts me genera el siguiente error, alguien puede ayudar porque y no me muestra la pagina correctamente ![](https://static.platzi.com/media/user_upload/image-f6aa38f0-fd1c-427d-a74b-47e3fc13755b.jpg)![]()
Buena noche, al ingresar el comando php artisan route:list no me arroja la lista sino un error que dice lo siguiente: Class "PageController" does not exist Alguien que por favor me indique que debo hacer en ese caso. Gracias

Routes: Route:resource acepta todas las rutas y podemos poner ->except['show'] al final para excluir una ruta en especifico.