andrelandgraf / laravel-docker

A walking skeleton for a web app using laravel 5.6 and docker.
2 stars 0 forks source link

Setting up first (show-off) component with tests, datamodel etc. #3

Open andrelandgraf opened 6 years ago

andrelandgraf commented 6 years ago

https://laravel-news.com/your-first-laravel-application

andrelandgraf commented 6 years ago

Creating a database table: docker-compose exec app php artisan make:migration create_pizza_table --create=pizza // Creates a migration file for the db table pizza

andrelandgraf commented 6 years ago

For the migration structure, see: https://laravel.com/docs/5.6/migrations

andrelandgraf commented 6 years ago

Creating a model and a factory for the table Pizza: docker-compose exec app php artisan make:model --factory Pizza

And a Seeder to add demo data: docker-compose exec app php artisan make:seeder PizzaTableSeeder

Also go to app/Pizza.php (the acutal model) and override the table name ($table), because default is plural form.

andrelandgraf commented 6 years ago

Refresh composer (do this whenever artisan tellls you it cannot find your new factory/seeder classes): docker-compose exec app composer dump-autoload Drop and refresh the dev database using the new seeder: docker-compose exec app php artisan migrate:fresh --seed

andrelandgraf commented 6 years ago

For a permanent connection to the app docker container use: docker-compose exec app bash -b Now you can use tinker to check the results for the seeding: https://scotch.io/tutorials/tinker-with-the-data-in-your-laravel-apps-with-php-artisan-tinker

andrelandgraf commented 6 years ago

Inside routes/web.php add your new data to a route (like App/Pizza::all()). Now you can access the data, inside your views (resources/views/).

andrelandgraf commented 6 years ago

Problem regarding importing js inside a lower level blade template: https://stackoverflow.com/questions/51592054/laravel-right-way-to-import-javascript-into-blade-templates

andrelandgraf commented 6 years ago

So far we can add and delete pizzas of the pizza table. Missing: