faraweilyas liked a comment+100 XP
1w ago
Thank you very much @jwmcpeak
I think importing data into tables is important and is found in almost every system today.
Maybe you should create a unique course for importing data
There are many points to touch on:
- insert/update
- Data validation
- jobs/batches
- queues
- Displaying the status to the front side
- Display the errors for each row
- Download a file with the errors
faraweilyas liked a comment+100 XP
1w ago
@gocanto You're right; I should've mentioned something about the dangers of disabling indexes and keys.
With saying that, however, anyone given a task such as this should do their due diligence on the data before any code is written, and definitely before any data is imported into the database. That would've been important to say and underscore in the video.
faraweilyas liked a comment+100 XP
1w ago
@jwmcpeak I Agree with you, but I would argue this is a learning platform. Nonetheless, I enjoy your videos :)
faraweilyas liked a comment+100 XP
1w ago
@gocanto And you would be correct to argue that. Good point =)
faraweilyas liked a comment+100 XP
3w ago
Use booted().
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
//
})
->booted(function (Application $app) {
EncryptCookies::except(config('...'));
})->create();
faraweilyas wrote a comment+100 XP
2mos ago
This can be improved to bring down queries count:
// phase 3
foreach ($orderItems as $item) {
OrderItem::create([
'order_id' => $order->id,
'product_id' => $item['product']->id,
'quantity' => $item['quantity'],
'price' => $item['price'],
'subtotal' => $item['subtotal'],
]);
$item['product']->decrement('stock_quantity', $item['quantity']);
// ...
}
Single query to create order line items:
$orderLineItems = collect($orderItems)->map(fn ($item) => [
'order_id' => $order->id,
'product_id' => $item['product']->id,
'quantity' => $item['quantity'],
'price' => $item['price'],
'subtotal' => $item['subtotal'],
]);
OrderItem::fillAndInsert($orderLineItems->toArray());
// can still be improved further by building an array of data we want to update first, then run a single mass update query
collect($orderItems)->each(fn ($item) => $item['product']->decrement('stock_quantity', $item['quantity']));
//...
faraweilyas liked a comment+100 XP
2mos ago
Nice reminder about handling race conditions.
Just a small suggestion regarding this statement:
$product = Product::where('id', $item->product_id)
->lockForUpdate()
->first();
That can be a bit simpler with whereKey:
$product = Product::whereKey($item->product_id)
->lockForUpdate()
->first();
faraweilyas wrote a comment+100 XP
4mos ago
This super powerful!
I have a suggestion though, this could be syntactic sugar....
we could have namespaced islands like so, using dot notation
@island(name: 'metrics.views-card')
<div class="metrics-card">
.....
</div>
@endisland
@island(name: 'metrics.visitors-card')
<div class="metrics-card">
.....
</div>
@endisland
Outside the islands
<!-- Target all islands -->
<button wire:click="refresh" wire:island="metrics.*">
Refresh All Metrics
</button>
<!-- Target dedicated islands -->
<button wire:click="refresh" wire:island="metrics.views-card">
Refresh views-card
</button>
<button wire:click="refresh" wire:island="metrics.visitors-card">
Refresh visitors-card
</button>
faraweilyas liked a comment+100 XP
4mos ago
Dude! This is awesome!
faraweilyas wrote a comment+100 XP
4mos ago
Hello,
as referenced in the laravel docs, i think you might have the values swapped around at 10:00
'balanceMaxShift' => 3,
'balanceCooldown' => 1,
laravel docs: https://laravel.com/docs/12.x/horizon#balancing-strategies
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
faraweilyas liked a comment+100 XP
5mos ago
In Laravel 12, the behavior you're observing with Pint is likely due to changes in the default code style configuration. Pint is a code formatting tool that adheres to a set of predefined rules, and these rules can change between versions to align with evolving best practices or community preferences.
To address your issue, you have a couple of options:
-
Customize Pint Configuration: You can customize the Pint configuration to match your preferred style. Pint uses a
.pint.jsonfile to define its rules. You can create or modify this file in the root of your project to specify your desired formatting rules.Here's an example of how you might configure Pint to adjust the formatting:
{ "preset": "laravel", "rules": { "method_argument_space": { "on_multiline": "ensure_fully_multiline" }, "single_quote": true, "lowercase_keywords": true } }Adjust the rules as needed to achieve the formatting style you prefer.
-
Check for Updates or Changes: Review the release notes or documentation for Laravel 12 and Pint to see if there are any mentions of changes to the default formatting rules. This can provide insight into why the formatting behavior has changed.
-
Revert to Previous Version: If the new formatting style is not acceptable and you prefer the previous behavior, you could consider reverting to the version of Pint used in Laravel 11. However, this is generally not recommended as it may lead to compatibility issues with other tools or libraries.
By customizing the Pint configuration, you can regain control over the formatting style to better suit your preferences.
faraweilyas liked a comment+100 XP
5mos ago
I'm creating a simple app with laravel 12, and I was writing the first tests, and I relized the pint does a weird formating.
it('Requires authentication ', function () {
get(route('dashboard'))->assertRedirect(route('login'));
});
In my previous app with laravel 11 app, pint formats the same code like this. Wich I personally find way better.
it('requires authentication', function () {
get(route('posts.create'))->assertRedirect(route('login'));
});
Is this a bug, or just a change on the default style?