Aprendiendo Laravel
Estoy aprendiendo laravel como entorno de trabajo para PHP, ya que tengo experiencia con el lenguaje. Además de seguir algunos tutoriales, tengo unos proyectos que vendrán a bien para migrar los a esta forma de trabajo.
Teniendo previamente instalado un servidor web con PHP y mySQL (por rapidez utilicé Xampp, aunque prefiero configurar lo todo por mí mismo), instalé Composer para poder instalar Laravel.
Una vez instalado, desde una ventana de comandos ingreso al subdirectorio donde colocaré mi proyecto (httdocs para este caso, por ser raíz de mi servidor web), ahí ejecuto el comando composer create-project laravel/laravel mi_proyecto donde "mi_proyecto" es el nombre que prefieras.
Las cosas que se me hacen interesantes son: Middleware, Controladores y Vistas (propio de la arquitectura MVC). Hice un pequeño ejercicio siguiento un tutorial, para este caso cree diferentes rutas y para cada una le agregué un código PHP que muestra algo en pantalla. Posteriormente lo cambié para que utilizara el middleware correspondiente, luego lo modifiqué para incluir el controlador, además del middleware. Finalmente lo modifiqué para utilizar la vista que toca a cada ruta.
Para continuar pongo mis códigos según fueron modificándose y hago comentarios al respecto.
php artisan make:middleware nombre_middleware Con esta instrucción genero los Middleware
php artisan make:controller nombre_controlador Con esta instrucción genero los controladores
I'm learning Laravel as a PHP framework, since I have experience with the language. In addition to following some tutorials, I have a few projects that will come well to migrate them to this way to work.
Having previusly installed a web server with PHP and mySQL (for rapidity I used Xampp, although I prefer to configure everything by myself), I installed Composer to be able to install Laravel.
Once installed, from a command line window, I changed my current directory to the subdirectory in which I put my project (httdocs for this case, because it's the root of my web server). There I execute the command composer create-project laravel/laravel my_project where "my_project" means whatever name you decide.
What is interesting to me are: Middleware, Controllers and Views (Own to MVC architecture). I made a little exercise following the tutorial, for this case I created different routes and for each I added a PHP code tha shows something in the screen. After that I changed it to will use the corresponding Middleware, then I modified it to include the controller, in addition to the middleware. Finally I changed it to use the"view" that belongs to each route.
To continue I put my source codes, according how they were modified.
php artisan make:middleware nombre_middleware With this instruction I generate the Middleware
php artisan make:controller nombre_controlador Wit this other I generate the controllers
Comentarios
Publicar un comentario