Saturday, May 19, 2018

create your first user in Laravel

So basically this blog is for a guy who popped into the Laravel Slack room and started blaming laravel with the most basic errors and saying that it is a Laravel issue. Many in the room tried to assist him but he refused to recognize his lack of understanding programming let alone his manners.

Installing and creating users in Laravel 5.6


First steps:


  1. Install MySQL 
    1. Windows
      1. Tutorial
    2. Linux (Ubuntu)
      1. Tutorial
  2. Install PHP
    1. Windows
      1. PHP 7.1 for windows
    2. Linux (Ubuntu)
      1. Tutorial
  3. Install Composer
    1. Windows
      1. Composer Installer
    2. Linux (Ubuntu)
      1. Tutorial
  4. Open a new terminal or command prompt and follow the following commands
    1. cd D:/sites
    2. composer global require "laravel/installer"
    3. composer create-project --prefer-dist laravel/laravel ProjectName
    4. cd ProjectName
    5. Windows
      1. copy .env.example .env
    6. Linux 
      1. cp .env.example .env
  5. Now go to the new file you created and edit it. you will find a section that looks like this
    1. DB_CONNECTION=mysql
    2. DB_HOST=127.0.0.1
    3. DB_PORT=3306
    4. DB_DATABASE=homestead
    5. DB_USERNAME=homestead
    6. DB_PASSWORD=secret
  6. change these according to the database you have already created
    1. See Step 1
  7. In your terminal/command prompt run the following
    1. php artisan make:auth
    2. php artisan migrate
    3. php artisan serve --port 80
  8. Open your web browser and go to http://localhost
    1. you will now see the laravel boiler plate. 
    2. you can click login or register and create users that easy
  9. What if you want to create your own users your own way (easy)
  10. Go back to your terminal / command prompt and run these commands
    1. ctrl + c -- to exit the serving command
    2. php artisan make:controller UserController --resource
  11. Now go to your project folder and navigate to app/http/controllers
    1. in this folder you will find your new PHP class / controller UserController
    2. navigate to the create method
    3. type the following code
      1. return view ('users.create');
  12. Now go to your root directory and go to resources/views 
    1. create a folder called users
    2. in the users folder create a file create.blade.php
  13. In the create.blade.php file create your html form method of post action of /users
    1. your form should include the following fields
      1. name
      2. email
      3. password
  14. go back to your UserController file
    1. go to the store method
    2. type the following code in the store method
    3. $user = new \App\User();
      $request->password = bcrypt($request->get('password'));
      $user->fill($request->all());
      $user->save();
      return view ('users.create');
  15. go back to the terminal / command prompt -- command time
    1. php artisan serve --port 808
  16. go to http://localhost/users/create
    1. fill your form and submit (should bring you back to your create form)
  17. go back to http://localhost
  18. log out (upper right)0
  19. login as your new user.
CONGRADUFUCKINGLATIONS

you just created your new user and users in laravel - the dirty way lol
Dedicated to
@Wotta
@Tom Ellis
@Mojtabaa 


No comments:

Post a Comment