安装项目
composer create-project laravel/laravel=5.5 --prefer-dist clog
git config user.name
git config user.email
git remote add origin
更换 github 账号后,总是提示旧的用户名被拒绝
remote: Permission to C-river/clog.git denied to 'old username'.
fatal: unable to access 'https://github.com/C-river/clog.git/': The requested URL returned error: 403
git config --system --unset credential.helper
App/Providers/AppServiceProvider.php
use Illuminiate/Support/Facades/Schema;
public function boot() {
Schema::defaultStringLength(191);
}
Eloquent 关联
一对一
hasOne
belongsTo (反向)
一对多
hasMany
belongsTo (反向)
多对多
belongsToMany
belongsToMany (反向)
中间表 pivot
多层一对多
Country
User
Post
class Country extends Model
{
public function posts() {
$this->hasManyThrough(User::class, Post::class);
}
}
多态一对多
posts
id - integer
title - string
body - text
videos
id - integer
title - string
url - string
comments
id - integer
body - text
commentable_id - integer
commentable_type - string
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
/**
* 获得拥有此评论的模型。
*/
public function commentable()
{
return $this->morphTo();
}
}
class Post extends Model
{
/**
* 获得此文章的所有评论。
*/
public function comments()
{
return $this->morphMany('App\Comment', 'commentable');
}
}
class Video extends Model
{
/**
* 获得此视频的所有评论。
*/
public function comments()
{
return $this->morphMany('App\Comment', 'commentable');
}
}
多对多多态关联
posts
id - integer
title - string
body - text
videos
id - integer
title - string
url - string
tags
id - integer
title - string
taggables
id - interger
taggable_id - integer
taggable_type - string
生成迁移文件 php artisan make:migration
生成模型文件 php artisan make:model
填充数据 php artisan make:seeder
database\factories\UserFactory.php
database\seeds\DatabaseSeeder.php
php artisan migrate:refresh --seed
这样后台的数据就基本有了,开始前台 vue 的开发
网友评论