clog 后台

安装项目
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 的开发

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容