composer安装:

composer require --dev phpunit/phpunit ^7

安装完成后验证:

./vendor/bin/phpunit --version

WX20181216-090235@2x.png

项目环境:

  • Mac OS Mojave 10.14.2
  • Laravel Valet 2.1.5
  • PHP 7.2.13
  • MySQL 5.7
    第一步:创建项目
laravel new forum

创建好了后,可以使用forum.test访问。
WX20181215-202253@2x.png
论坛数据库设计:
1.帖子(Thread)
2.回复(Reply)
3.用户(User)
A.帖子是由用户创建的
B.回复属于帖子,也属于用户

cd forum

第二步:创建数据模型

php artisan make:model Thread -mr

修改database下migrations下面的create_threads_table后缀的文件,增加如下字段:

 $table->integer('user_id');
 $table->string('title');
 $table->text('body');

修改.env文件重的数据库配置:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=forum
DB_USERNAME=root
DB_PASSWORD=Lei.110120

我的数据库密码已经修改过了,如果没有,请留空。
创建数据库:打开终端shell

mysql -uroot -pLei.110120
create database forum

最后migrate:

php artisan migrate

创建成功后如下图:
WX20181215-205305@2x.png
继续创建回复Reply:

php artisan make:model Reply -mc

修改database下migrations下面的create_replies_table后缀的文件,增加如下字段:

$table->integer('thread_id' );
$table->integer('user_id');
$table->text('body');

执行migrate:

php artisan migrate

创建工厂测试:

php artisan make:factory ThreadFactory --model=Thread

修改database下面生成的ThreadFactory.php文件:

<?php

use Faker\Generator as Faker;

$factory->define(App\Thread::class, function (Faker $faker) {
    return [
        'user_id' => function(){
        return factory('App\User')->create()->id;
        },
        'title' => $faker->sentence,
        'body' => $faker->paragraph,
    ];
});

创建数据:

php artisan tinker
factory('App\Thread',50)->create()

这里设置了50条数据。
完成后查看数据库如下图:
WX20181215-221339@2x.png
继续给Reply设置工程:

php artisan make:factory ReplyFactory --model=Reply

修改database下面生成的ReplyFactory.php文件:

<?php

use Faker\Generator as Faker;

$factory->define(App\Reply::class, function (Faker $faker) {
    return [
        'thread_id' => function(){
            return factory('App\Thread')->create()->id;
        },
        'user_id' => function(){
            return factory('App\User')->create()->id;
        },
        'body' => $faker->paragraph,
    ];
});

先清除一下数据:

php artisan migrate:refresh

创建数据:

php artisan tinker
$threads = factory('App\Thread',50)->create()
$threads->each(function ($thread){ factory('App\Reply',10)->create(['thread_id'=> $thread->id]);});

第三条命令的意思是给每个thread创建了10条reply。
效果如下图:
WX20181215-223637@2x.png

将以下代码加入到header.php文件中:

<?php $this->widget('Widget_Metas_Category_List')->to($category); ?>

<?php while($category->next()): ?>

<a<?php if($this->is('category', $category->slug)): ?> class="current"<?php endif; ?> href="<?php $category->permalink(); ?>" title="<?php $category->name(); ?>"><?php $category->name(); ?></a>

<?php endwhile; ?>

WX20181214-212515@2x.png

使用中科大源
(1)替换默认源
第一步:替换brew.git

cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git

第二步:替换homebrew-core.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
cd 
brew update

(2)替换Homebrew Bottles源

Homebrew是OS X系统的一款开源的包管理器。出于节省时间的考虑,Homebrew默认从Homebrew Bottles源中下载二进制代码包安装。Homebrew Bottles是Homebrew提供的二进制代码包,目前镜像站收录了以下仓库:
homebrew/homebrew-core
homebrew/homebrew-dupes
homebrew/homebrew-games
homebrew/homebrew-gui
homebrew/homebrew-python
homebrew/homebrew-php
homebrew/homebrew-science
homebrew/homebrew-versions
homebrew/homebrew-x11

对于bash用户:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

对于zsh用户

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

2.使用清华源
(1)替换默认源
第一步:替换现有上游

cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
cd 
brew update

第二步:使用homebrew-science或者homebrew-python

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-science"

git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-science.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-python"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-python.git
cd 
brew update

(2)替换Homebrew Bottles源

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

3.在中科大源或清华源失效或宕机时可以切换回官方源
第一步:重置brew.git

cd "$(brew --repo)"
git remote set-url origin https://github.com/Homebrew/brew.git

第二步:重置homebrew-core.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://github.com/Homebrew/homebrew-core.git
cd
brew update

第三步:注释掉bash配置文件里的有关Homebrew Bottles即可恢复官方源。 重启bash或让bash重读配置文件。

作者:零尾
来源:CSDN
原文:https://blog.csdn.net/lwplwf/article/details/79097565

1、安装homebrew (mac缺失的软件包管理器)

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2、确保80端口不被占用
3、安装Valet

brew update
brew install php@7.2
brew link --force php@7.2
composer global require laravel/valet

注意:确保~/.composer/vendor/bin 在系统的PATH目录中,使用下面的命令:

echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.zshrc