12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace Illuminate\Tests\Integration\Database\EloquentMorphToTouchesTest;
- use DB;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Schema\Blueprint;
- use Illuminate\Support\Facades\Schema;
- use Illuminate\Tests\Integration\Database\DatabaseTestCase;
- class EloquentMorphToTouchesTest extends DatabaseTestCase
- {
- protected function defineDatabaseMigrationsAfterDatabaseRefreshed()
- {
- Schema::create('posts', function (Blueprint $table) {
- $table->increments('id');
- $table->timestamps();
- });
- Schema::create('comments', function (Blueprint $table) {
- $table->increments('id');
- $table->nullableMorphs('commentable');
- });
- Post::create();
- }
- public function testNotNull()
- {
- $comment = (new Comment)->commentable()->associate(Post::first());
- DB::enableQueryLog();
- $comment->save();
- $this->assertCount(2, DB::getQueryLog());
- }
- public function testNull()
- {
- DB::enableQueryLog();
- Comment::create();
- $this->assertCount(1, DB::getQueryLog());
- }
- }
- class Comment extends Model
- {
- public $timestamps = false;
- protected $touches = ['commentable'];
- public function commentable()
- {
- return $this->morphTo(null, null, null, 'id');
- }
- }
- class Post extends Model
- {
- //
- }
|