美文网首页
laravel 9.7 发布

laravel 9.7 发布

作者: 追梦人在路上不断追寻 | 来源:发表于2022-04-07 22:38 被阅读0次

    Laravel 团队发布了 Laravel v9.7.0,其中包含一个() route 参数约束方法、一个 Str: : squish () helper、 JSON 路径查询增强等.

    Query Builder whereBelongsTo() Accepts Collections

     // Previously 
    $query->whereBelongsTo($category[0]) 
    ->orWhereBelongsTo($category[1]) 
    
    // Or... 
    $query->whereIn('category_id', $categories->modelKeys()); 
    
    // >=9.7 can use collections:
    
    $query->whereBelongsTo($categories);
    $query->whereBelongsTo($categories, 'category');
    

    Database Queries Containing Json Paths Support Array Index Braces

    DB::table('json_table')->where('column->json_option[0]', 'foo')->update(['column->json_option[0]', => 'bar']);
    

    Routing Event Fires Before Route Matched

    use Illuminate\Routing\Events\Routing;
    Event::listen(function (Routing $event) {
    
    });
    

    Route whereIn() Parameter Constraint Method

    Route::get('/foo/{bar}')->whereIn('bar', $values);
    

    Batch Job Delay for Beanstalkd and SQS Queues

    use App\Jobs\ImportCsv;
    use Illuminate\Bus\Batch;
    use Illuminate\Support\Facades\Bus;
    $batch = Bus::batch([ 
        (new ImportCsv(1, 100))->delay($delay), 
        (new ImportCsv(101, 200))->delay($delay)
    ])->dispatch();
    

    String Squish Helper

    $this->assertSame( 'laravel php framework', Str::squish(' laravel php framework ')); 
    $this->assertSame( 'laravel php framework', Str::squish("laravel\t\tphp\n\nframework") ); 
    $this->assertSame('laravel php framework',Str::squish('
        laravel 
        php 
        framework
    '));
    

    Query Builder "whereJsonContainsKey()" Method

    DB::table('users')->whereJsonContainsKey('options->languages')->get(); 
    DB::table('users')->whereJsonDoesntContainKey('options->language->primary')->get(); 
    DB::table('users')->whereJsonContainsKey('options->fa[0]')->get();
    DB::table('users')->whereJsonDoesntContainKey('options->fa[0][1]')->get();
    

    Dispatch Batch After a Response

    $batch = Bus::batch([ 
    new ImportCsv(1, 100), 
    new ImportCsv(101, 200), 
    new ImportCsv(201, 300), 
    new ImportCsv(301, 400), 
    new ImportCsv(401, 500), ])->then(function (Batch $batch) { 
    // All jobs completed successfully...
     })->catch(function (Batch $batch, Throwable $e) {
     // First batch job failure detected...
    })->finally(function (Batch $batch) {
     // The batch has finished executing...
    })->dispatchAfterResponse();
    // also, it returns a batch object so you can access batch id 
    return $batch->id;
    

    laravel 9.7改进了许多,变得越来越好用了。

    相关文章

      网友评论

          本文标题:laravel 9.7 发布

          本文链接:https://www.haomeiwen.com/subject/omqesrtx.html