΢ Ͷ ^ ھ

cba上海男篮赛程 :Laravel5.1 ģͶBP“÷

cba㶫 www.axwwg.com  •rg2020-01-24 13:00:35   ߣ   ҪuՓ(0)

ČvLaravel5.1 ģͶBP“÷oҹ҅w£
ʲôǶBP“ һˣñfuՓ Ԍҕl Ҳ

ČvLaravel5.1 ģͶBP“÷oҹ҅w£

ʲôǶBP“ һˣñfuՓ Ԍҕl ҲԌЂ uՓȡҕlĔ@ҪõBP“

εһԒYһ팦ɏ

1 FBP“

1.1 ±ĽY

  public function up()
  {
    Schema::create('articles', function (Blueprint $table) {
      $table->increments('id');
      $table->string('title');
      $table->text('body');$table->timestamps();
    });
  }

1.2 ҕlY

  public function up()
  {
    Schema::create('videos', function (Blueprint $table) {
      $table->increments('id');
      $table->string('title');
      $table->text('description');
      $table->timestamps();
    });
  }

1.3 uՓY

  public function up()
  {
    Schema::create('comments', function (Blueprint $table) {
      $table->increments('id');
      $table->text('content');
      $table->integer('item_id');
      $table->string('item_type');
      $table->timestamps();
    });
  }

@Ҫָ item_id item_type һBһ item_type ҪDž^eP“Ǐ ҂@ֻЃɂֵApp\Article App\Video

1.4 BP“

Article Video

  public function comments()
  {
    /**
     * ڶ:ǰYitem_ ô͌item DŽeľ͌e
     * :item_type
     * Ă:item_id
     * 傀:P“ǂI
     * (ϳ˵ڶʡ)
     */
    return $this->morphMany(Comment::class, 'item', 'item_type', 'item_id', 'id');
  }

Comment

  public function video()
  {
    /**
     * ʡ ^Kh߀njȫ
     */
    return $this->morphTo('item', 'item_type', 'item_id');
  }

ʹã

Route::get('/', function () {
  $video = App\Video::find(8);
  foreach ($video->comments as $comment) {
    echo $comment->id . ": " . $comment->item_type;
  }
});

PLaravelPݸdȤx߿ɲ鿴վ}LaravelTcMA̡̳php_lܿYphpOӋT̡̳php+mysqlT̡̳phpҊɅR

ϣһLaravelܵPHPOӋ

ܸdȤ:

  • Laravel P“ģ-P“P“µķ
  • LaravelP“ģ^VYյĽY(haswith^e)
  • laravelW̳֮P“ģ
  • LaravelȿģP“ĿԜ\
  • Laravel EloquentֱʹģP“ČF
  • Laravel ģP“A̳Ԕ
  • Laravel5.1 ģhһPϵ
  • Laravel5.1 ģһһPϵFcʹ÷
  • Laravel5.1 ģͲԃxc÷
  • Laravel5.1 ģ̈́cʹ÷
  • Laravel5.1 P“ģ֮

P

  • Laravel5.1 ģͶBP“÷

    Laravel5.1 ģͶBP“÷

    ČvLaravel5.1 ģͶBP“÷oҹ҅w£ ʲôǶBP“ һˣñfuՓ Ԍҕl Ҳ
    2020-01-24
  • Laravel5.1 P“ģ֮

    Laravel5.1 P“ģ֮

    ČvLaravel5.1 P“ģ֮oҹ҅w£ ֮ǰ^PģP“ĹPӛģP“úһЩʹÛ]нBa
    2020-01-24
  • laravel܌Wӛ֮βԔ

    laravel܌Wӛ֮βԔ

    Čvlaravel܌Wӛ֮βoҹ҅w£ 1MVC õһlaravelĿŪՈ
    2020-01-24
  • Laravel5.1 ܷչʾF

    Laravel5.1 ܷչʾF

    ČvLaravel5.1 ܷչʾFoҹ҅w£ Laravel҂ṩһ׷퓵߉݋҂oԼF߉݋ֻҪЎ
    2020-01-24
  • PHP׃ȫ׃&ֲ׃&global&staticPI÷

    PHP׃ȫ׃&ֲ׃&global&staticPI÷

    ČvPHP׃ȫ׃&ֲ׃&global&staticPI÷oҹ҅w£ ҂֪׃䌍ஔ҂Á탦Ϣ
    2020-01-24
  • thinkphp{sqlserver^̷ضY

    thinkphp{sqlserver^̷ضY

    ȰbUչ windows ֞ɂE ҵԼPHP汾pdoUչd≺php.ini憢ÔUչ,ҪעĆ}php汾ԼǷ鰲ȫ汾
    2020-01-24
  • Laravel·cMVCԔ

    Laravel·cMVCԔ

    ČvLaravel·cMVCoҹ҅w£ 1· ·ɵþnjÑIJͬurlՈDloijM̎laravel·ɶx
    2020-01-24
  • Laravel5.1 ܵ䛺עԌFԔ

    Laravel5.1 ܵ䛺עԌFԔ

    ČvLaravel5.1 ܵ䛺עԌFoҹ҅w£ Pڵ䛺ע LaravelԎһ׽MF@һ҂ֻҪFε
    2020-01-24
  • PHP߼֮ϢԭcFԔ

    PHP߼֮ϢԭcFԔ

    ČvPHP߼֮ϢԭcFoҹ҅w£ 1. ʲôϢ ϢУӢZMessage queueһNMgͨŻͬ
    2020-01-24
  • phpstormME̳Ԕ

    phpstormME̳Ԕ

    PhpstormǴPHPT۲ֵһaļ_l֧PHPZԹ ṩĴaaȫؘre`AȵȹnjһЩphp
    2020-01-24