1. 建立專案

composer self-update

composer create-project prefer-dist laravel/laravel 你自己命名 5.2.29

 

2.設定網址

windows/system32/drivers/etc/hosts

127.0.0.1 你自己命名的網址

xampp/apache/cong/extra/httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/你自己命名的專案資料夾/public"
    ServerName 你自己命名的網址
</VirtualHost>

 

3.去phpmyadmin建立資料庫

CREATE DATABASE 你命名的資料庫名稱 CHARACTER SET utf8 COLLATE utf8_general_ci;

 

4.設定env

資料庫名稱和帳號密碼

 

5.php artisan migrate

建立資料庫表格

 

6.php artisan make:auth

建立會員系統

 

7.建立view

    目錄: C:\xampp\htdocs\專案資料夾\resources\views\admin

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----      2017/10/1  上午 11:29                categories
d-----      2017/10/1  上午 11:29                posts
d-----      2017/10/1  上午 11:30                users
-a----      2017/10/1  上午 11:25              0 index.blade.php

    目錄: C:\xampp\htdocs\專案資料夾\resources\views\admin\categories

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----      2017/10/1  上午 11:29              0 edit.blade.php
-a----      2017/10/1  上午 11:26              0 index.blade.php

    目錄: C:\xampp\htdocs\專案資料夾\resources\views\admin\posts

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----      2017/10/1  上午 11:29              0 create.blade.php
-a----      2017/10/1  上午 11:29              0 edit.blade.php
-a----      2017/10/1  上午 11:26              0 index.blade.php

    目錄: C:\xampp\htdocs\專案資料夾\resources\views\admin\users

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----      2017/10/1  上午 11:30              0 create.blade.php
-a----      2017/10/1  上午 11:30              2 edit.blade.php
-a----      2017/10/1  上午 11:26              0 index.blade.php

 

8.進行git做版本控制

8-1.git init

8-2.git add .

8-3. git commit -m '打一些話'

8-4.git log,就可以看到那個亂數(就可以rollback了)

 

9.增加會員權限相關表格

            //更改user的migration
            $table->integer('role_id')->index()->unsigned()->nullable();
            $table->integer('is_active')->default(0);

10.增加一個Role model,並migrate

php artisan make:model Role -m

//更改role的migration
$table->string('name');

11.建立關聯

//修改user的model,一個會員只能有一個階級
    public function role(){
        return $this->belongsTo('App\Role');
    }

12.php artisan migrate:refresh

13.增加一些資料

INSERT INTO `roles` (`id`, `name`, `created_at`, `updated_at`) VALUES
(1, '管理者', NULL, NULL),
(2, '使用者', NULL, NULL),
(3, '訂閱者', NULL, NULL);

14.從前台建立一個使用者

//讓這個會員變成管理者
UPDATE `users` SET `role_id` = '1' WHERE `users`.`id` = 1;
//啟用這個會員
UPDATE `users` SET `is_active` = '1' WHERE `users`.`id` = 1;

 

15.使用tinker

php artisan tinker

建立一個user物件

$user=App\User::find(1); //找到一號

App\User::create(['name'=>'阿福','email'=>'fu@gmail.com']) //增加一個新使用者

 

16.更改routes

5.2版的位置在app/http/裡面

Route::resource('admin/users', 'AdminUsersController');

 

17.增加一個controller

php artisan make:controller --resource AdminUsersController

 

18.輸入php artisan route:list ,會發現有很多method可以用了

 

 

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Jerry 的頭像
    Jerry

    Bug倉庫 // 程式日記

    Jerry 發表在 痞客邦 留言(0) 人氣()