Laravel v7.7 publishing container supports variable parameters

Keywords: PHP Laravel firewall SQL

The Laravel team yesterday released v7.7.0, which includes container supported constructors supporting variable parameters, some new HTTP client functions, Blueprint's new rawIndex() method and all the latest functions in the 7.x branch. Repair and change:

HTTP client GET request support array

Daniel Mason contributed to the HTTP client's support for arrays:

Http::get('http://foo.com', ['foo' => 'bar']);

Http::assertSent(function (Request $request) {
    return $request->url() === 'http://foo.com/get?foo=bar'
        && $request['foo'] === 'bar';
});

HTTP client adds assertSentCount assertion

Christoph Rumpel adds an assertSentCount assertion to the HTTP client, which is useful for asserting the expected request value sent:

$this->factory->fake();

$this->factory->assertSentCount(0);

$this->factory->post('http://foo.com/form', [
       'name' => 'Taylor',
]);

$this->factory->assertSentCount(1);

$this->factory->post('http://foo.com/form', [
       'name' => 'Jim',
]);

$this->factory->assertSentCount(2);

The "rawIndex" method can use expressions to create indexes

Jonathan Reinink contributes the rawIndex method, which allows us to create indexes using custom SQL expressions:

// Before
Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->date('birth_date')->nullable();
    $table->timestamps();
});

DB::statement('ALTER TABLE users ADD INDEX birthday_index ((date_format(birth_date, "%m-%d")))');

// After
Schema::create('users', function (Blueprint $table) {
    $table->id();
    $table->string('name');
    $table->date('birth_date')->nullable();
    $table->timestamps();

    $table->rawIndex('(date_format(birth_date, "%m-%d"))', 'birthday_index');
});

Container constructor supports variable parameters

Beau Simensen added the variable parameter function to the container. Here is a simple use case:

// Before
app()->singleton(Logger::class, MyLogger::class);
app()->bind(Firewall::class, function ($c) {
    return new Firewall(
        $c->make(Logger::class),
        ...[
            $c->make(NullFilter::class),
            $c->make(ProfanityFilter::class),
            $c->make(TooLongFilter::class),
        ]
    );
});

// After
app()->singleton(Logger::class, MyLogger::class);
app()
    ->when(Firewall::class)
    ->needs(Filter::class)
    ->give([
        NullFilter::class,
        ProfanityFilter::class,
        TooLongFilter::class,
    ]);

Like pull request As described in, you can also pass closures to the give method:

app()->singleton(Logger::class, MyLogger::class);
app()
    ->when(Firewall::class)
    ->needs(Filter::class)
    ->give(function ($c) {
        return [
            $c->make(NullFilter::class),
            $c->make(ProfanityFilter::class),
            $c->make(TooLongFilter::class),
        ];
    });

pull request Contains all details, and other issues that can be resolved.

 

HTTP client adds "hasHeaders" assertion

Matt kingshort has added the hasHeaders() method for HTTP clients, which allows you to use some syntax sugar to check the existing request headers or values:

$headers = [
    'X-Test-Header' => 'foo',
    'X-Test-ArrayHeader' => ['bar', 'baz'],
];

Http::withHeaders($headers);

// ...
Http::assertSent(function ($request) use ($headers) {
    return $request->hasHeaders($headers);
});

Release notes

You can see some new features and 7.6.0 and 7.7.0 The difference between. Full release notes can be found in v7 changelog See:

v7.7.0

 

Newly added

  • HTTP client GET request support array( #32401)
  • Add Illuminate\Http\Client\Factory::assertSentCount()( #32407)
  • Add Illuminate\Database\Schema\Blueprint::rawIndex()( #32411)
  • Eloquest builder add getGrammar to passthru( #32412)
  • storage:link command adds -- relative parameter( #3245724b705e)
  • New dynamic column key for foreign key constraint( #32449)
  • New variable parameter support for container( #324541dd6db3)
  • Add Illuminate\Http\Client\Request::hasHeaders()( #32462)

repair

  • Fix the MorphPivot::delete() function BUG with the primary key model( #32421)
  • An exception will be thrown if the container call lacks the necessary parameters( #3243944c2a8d)
  • Repair HTTP client multipart request( #324281f163d4)
  • Repair Illuminate\Support\Stringable::isEmpty()( #32447)
  • Fix where null / where not null json fields supporting MySQL( #32417d3bb329)
  • Fix callback used by Collection::orderBy()( #32471)

change

  • Compileroutecollection re enable Router::newRoute()( #32416)
  • Higher illuminate \ queue \ interactionwithqueue. PHP:: $job is public( 2e272ee)
  • Catch and report exceptions during scheduled task run( #32461)

 

Original address: https://laravel-news.com/laravel-7-7-rel...
Translation address: https://learnku.com/laravel/t/43581

For more information, please visit:

Tencent T3-T4 standard boutique PHP architect tutorial directory, as long as you read it to ensure a higher salary (continuous update)

Posted by busyguy78 on Thu, 23 Apr 2020 00:00:00 -0700