Created
May 13, 2019 07:21
-
-
Save rentalhost/a4b2446e3c772a3c14ababd990e5c7a9 to your computer and use it in GitHub Desktop.
Laravel #28506
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types = 1); | |
namespace App; | |
use Illuminate\Database\Eloquent\Model; | |
use Illuminate\Database\Eloquent\SoftDeletes; | |
class Example | |
extends Model | |
{ | |
use SoftDeletes; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types = 1); | |
use Illuminate\Database\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Support\Facades\Schema; | |
class ExamplesTable | |
extends Migration | |
{ | |
public function down(): void | |
{ | |
Schema::dropIfExists('examples'); | |
} | |
public function up(): void | |
{ | |
Schema::create('examples', static function (Blueprint $table) { | |
$table->bigIncrements('id'); | |
$table->timestamps(); | |
$table->softDeletes(); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types = 1); | |
namespace Tests\Unit; | |
use App\Example; | |
use Illuminate\Support\Facades\DB; | |
use Tests\TestCase; | |
class ExampleTest | |
extends TestCase | |
{ | |
public function testQuery(): void | |
{ | |
DB::table('examples')->truncate(); | |
// Example case. | |
$example = new Example; | |
$example->deleted_at = now(); | |
$example->save(); | |
// OK: | |
$this->assertSame(/** @lang text */ 'select * from `examples` where `examples`.`deleted_at` is null', Example::query()->toSql()); | |
// Fail: it returns only "select * from `examples`", ignoring the SoftDeletes -- and all others -- scopes. | |
$this->assertSame(/** @lang text */ 'select * from `examples` where `examples`.`deleted_at` is null', Example::query()->getQuery()->toSql()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment