DEV Community

Morcos Gad
Morcos Gad

Posted on

New Things Added - Laravel 9.7 Released

Let's get started quickly I found new things in Laravel 9.7 Released I wanted to share with you.

// 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');
Enter fullscreen mode Exit fullscreen mode

Image description

  • 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']);
Enter fullscreen mode Exit fullscreen mode
Route::get('/foo/{bar}')->whereIn('bar', $values);
Enter fullscreen mode Exit fullscreen mode
$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
    ')
);

use Illuminate\Support\Str;
$string = Str::squish('    laravel    framework    ');
// laravel framework
Enter fullscreen mode Exit fullscreen mode
DB::table('users')
    ->whereJsonContainsKey('options->languages')
    ->get();

DB::table('users')
    ->whereJsonDoesntContainKey('options->language->primary')
    ->get();

DB::table('users')
    ->whereJsonContainsKey('options->2fa[0]')
    ->get();

DB::table('users')
    ->whereJsonDoesntContainKey('options->2fa[0][1]')
    ->get();
Enter fullscreen mode Exit fullscreen mode
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();
Enter fullscreen mode Exit fullscreen mode
DB::table('users')->whereNotNull('name')->get();
Enter fullscreen mode Exit fullscreen mode

I hope you enjoyed with me and to learn more about this release visit the sources and search more. I adore you who search for everything new.
Source :- https://laravel-news.com/laravel-9-7-0
Source :- https://www.youtube.com/watch?v=tQ2DG-qP6ik

Top comments (2)

Collapse
 
kevincp17 profile image
kevincp17

Nice, thanks for the update Morcos.

Collapse
 
eshimischi profile image
eshimischi

9.8.1 already. Just updated my stack