Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to update any section of package.json #25783

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 7 additions & 19 deletions src/Illuminate/Database/Eloquent/Relations/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,24 +235,6 @@ public function touch()
}
}

/**
* Remove all or passed registered global scopes.
*
* @param array|null $scopes
* @return $this
*/
public function withoutGlobalScopes(array $scopes = null)
{
$this->getQuery()->withoutGlobalScopes($scopes);

$this->macroBuffer[] = [
'method' => __FUNCTION__,
'parameters' => [$scopes],
];

return $this;
}

/**
* Get the foreign key "type" name.
*
Expand Down Expand Up @@ -298,7 +280,13 @@ protected function replayMacros(Builder $query)
public function __call($method, $parameters)
{
try {
return parent::__call($method, $parameters);
$result = parent::__call($method, $parameters);

if (in_array($method, ['select', 'selectRaw', 'selectSub', 'addSelect', 'withoutGlobalScopes'])) {
$this->macroBuffer[] = compact('method', 'parameters');
}

return $result;
}

// If we tried to call a method that does not exist on the parent Builder instance,
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn
*
* @var string
*/
const VERSION = '5.7.5';
const VERSION = '5.7.6';

/**
* The base path for the Laravel installation.
Expand Down
6 changes: 2 additions & 4 deletions src/Illuminate/Foundation/Console/Presets/Preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ protected static function ensureComponentDirectoryExists()
/**
* Update the "package.json" file.
*
* @param bool $dev
* @param string $configurationKey
* @return void
*/
protected static function updatePackages($dev = true)
protected static function updatePackages($configurationKey = 'devDependencies')
{
if (! file_exists(base_path('package.json'))) {
return;
}

$configurationKey = $dev ? 'devDependencies' : 'dependencies';

$packages = json_decode(file_get_contents(base_path('package.json')), true);

$packages[$configurationKey] = static::updatePackageArray(
Expand Down
91 changes: 91 additions & 0 deletions tests/Integration/Database/EloquentMorphToSelectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace Illuminate\Tests\Integration\Database\EloquentMorphToSelectTest;

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Tests\Integration\Database\DatabaseTestCase;

/**
* @group integration
*/
class EloquentMorphToSelectTest extends DatabaseTestCase
{
public function setUp()
{
parent::setUp();

Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});

Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->string('commentable_type');
$table->integer('commentable_id');
});

$post = Post::create();
(new Comment)->commentable()->associate($post)->save();
}

public function test_select()
{
$comments = Comment::with('commentable:id')->get();

$this->assertEquals(['id' => 1], $comments[0]->commentable->getAttributes());
}

public function test_select_raw()
{
$comments = Comment::with(['commentable' => function ($query) {
$query->selectRaw('id');
}])->get();

$this->assertEquals(['id' => 1], $comments[0]->commentable->getAttributes());
}

public function test_select_sub()
{
$comments = Comment::with(['commentable' => function ($query) {
$query->selectSub(function ($query) {
$query->select('id');
}, 'id');
}])->get();

$this->assertEquals(['id' => 1], $comments[0]->commentable->getAttributes());
}

public function test_add_select()
{
$comments = Comment::with(['commentable' => function ($query) {
$query->addSelect('id');
}])->get();

$this->assertEquals(['id' => 1], $comments[0]->commentable->getAttributes());
}

public function test_lazy_loading()
{
$comment = Comment::first();
$post = $comment->commentable()->select('id')->first();

$this->assertEquals(['id' => 1], $post->getAttributes());
}
}

class Comment extends Model
{
public $timestamps = false;

public function commentable()
{
return $this->morphTo();
}
}

class Post extends Model
{
}