美文网首页
Recipe-box 模型设计(laravel&vue)

Recipe-box 模型设计(laravel&vue)

作者: 三仕贰號 | 来源:发表于2018-01-05 16:40 被阅读0次

创建数据库模型(创建完成之后可在 database/migrations 下看到创建的文档)

>php artisan make:model Recipe -m

>php artisan make:model RecipeIngredient -m

>php artisan make:model RecipeDirection -m

修改用户模型(路径 database/migrations/2014_10_12_000000_create_users_table.php)

在up方法下添加一行

$table->string('api_token')->nullable();

修改 Recipe 模型 下的up 方法(路径 database/migrations/2017_07_13_031833_create_recipes_table.php)

public function up() {

    Schema::create('recipes', function (Blueprint $table) {

        $table->increments('id');

        $table->integer('user_id')->unsigned();

        $table->string('name');

        $table->text('description');

        $table->string('image');

        $table->timestamps();

    });

}

修改 recipe_ingredients 模型 下的up 方法(路径 database/migrations/2017_07_13_031921_create_recipe_ingredients_table.php)

public function up() {

    Schema::create('recipe_ingredients', function (Blueprint $table) {

        $table->increments('id');

        $table->integer('recipe_id')->unsigned();

        $table->string('name');

        $table->string('qty');

    });

}

修改 recipe_directions 模型 下的up 方法(路径 database/migrations/2017_07_13_031952_create_recipe_directions_table.php)

public function up() {

    Schema::create('recipe_directions', function (Blueprint $table) {

        $table->increments('id');

        $table->integer('recipe_id')->unsigned();

        $table->string('description');

    });

}

修改 recipe.php 文件下的 Recipe 类(路径 app/Recipe.php)

class Recipe extends Model{

    protected $fillable = [ 'name', 'description', 'image' ];

    public function user() {

        return $this->belongsTo(User::class);

    }

    public function ingredients(){

        return $this->hasMany(RecipeIngredient::class);

    }

    public function directions(){

        return $this->hasMany(RecipeDirection::class);

    }

    public static function form(){

        return [

            'name' => '',

            'description' => '',

            'image' => '',

            'ingredients' => [ RecipeIngredient::form() ],

            'directions' => [ RecipeDirection::form(), RecipeDirection::form() ] ];

    }

}

修改 RecipeDirection.php文件下的 RecipeDirection 类(路径 app/RecipeDirection.php)

class RecipeDirection extends Model {

    protected $fillable = [ 'description' ];

    public $timestamps = false;

    public static function form(){

        return [ 'description' => '' ];

    }

}

修改 RecipeIngredient.php文件下的 RecipeIngredient 类(路径 app/RecipeIngredient.php )

class RecipeIngredient extends Model {

    protected $fillable = [ 'name', 'qty' ];

    public $timestamps = false;

    public static function form(){

        return [ 'name' => '', 'qty' => '' ];

    }

}

修改 User.php 文件 User类(路径:app/User.php)

class User extends Authenticatable {

    use Notifiable;

    protected $fillable = [ 'name', 'email', 'password', 'api_token' ];

    protected $hidden = [ 'password', 'remember_token','api_token' ];

    public function recipes(){

        return $this->hasMany(Recipe::class);

    }

}

相关文章

  • Recipe-box 模型设计(laravel&vue)

    创建数据库模型(创建完成之后可在 database/migrations 下看到创建的文档) >php artis...

  • 【孟母堂】细节设计模型

    楼梯扶手 窗户图案模型 房屋顶部设计模型 房屋墙面设计模型 走廊设计模型 门设计模型 屋脊设计模型 具体细节逐步完...

  • Recipe-box 控制器设计

    创建控制器(创建完成之后生成的文件在 app/Http/Controllers/ 下) 添加路由 (路径:rout...

  • MySQL--进阶

    数据库设计 需求分析 需求设计 概要设计 抽取实体:业务模型->实体模型(类) 数据库设计:业务模型/实体模型->...

  • 黑马基础

    软件开发过程模型: 瀑布模型,快速模型,螺旋模型 测试模型: V模型:需求分析、概要设计、详细设计、编码、单元测试...

  • 03-商品功能的设计

    一 商品模型的设计 商品的模型设计,包含商品的数据设计,商品的类型。 TypeInfo模型类中有title,isD...

  • 模型设计

    一、模型整体设计 二、模型说明 该设计参考现在比较通用的权限管理设计模式,权限管理模型包括 2.1 用户表 ...

  • DDD碎片记录 03. 贫血模型与充血模型

    将业务领域模型转换为程序设计 一般有2种设计思路:贫血模型,充血模型 所谓贫血模型,就是在软件设计中有很多POJO...

  • PowerDesigner 概念模型(CDM)的 Notatio

    在进行数据库设计模型时,分为概念模型设计和物理模型设计两种,概念模型主要是反映真是世界中的业务关系,也就是我们常用...

  • DDD 读书笔记(三)

    第三章主要介绍了模型和实现绑定的重要性以及实践方法。 模型驱动设计 模型驱动设计强调的是分析模型和程序设计不分离的...

网友评论

      本文标题:Recipe-box 模型设计(laravel&vue)

      本文链接:https://www.haomeiwen.com/subject/zgxnixtx.html