Posts

Since 2024
A Look at What's Coming to PHP 8.4
A Look at What's Coming to PHP 8.4

PHP 8.4 is coming soon and in this post let's look at what has been announced so far, and what new features you might expect. When is PHP 8.4 scheduled to be released? PHP 8.4 is scheduled to be released on November 21, 2024. Before the release it will feature 6 months of pre-release phases going from Alphas, to Betas, to Release Candidates, and then the official release. PHP Property Hooks Property hooks are inspired by languages like Kotlin, C#, and Swift, and the syntax includes two syntax variants that resemble short and multi-line closures: class User implements Named { private bool $isModified = false; public function __construct( private string $first, private string $last ) {} public string $fullName { // Override the "read" action with arbitrary logic. get => $this->first . " " . $this->last; // Override the "write" action with arbitrary logic. set { [$this->first, $this->last] = explode(' ', $value, 2); $this->isModified = true; } } } Property hooks will help remove boilerplate of property getters and setters, allowing a property to define access and updates using hooks. Check out our post for more details: Property Hooks in PHP 8.4. new MyClass()->method() without parentheses Since member access during instantiation was introduced, you must wrap the new MyClass() call in parentheses, or you'll get a parse error. The proposed syntax would allow you to access constants, properties, and methods without the extra parentheses: // Wrapping parentheses are required to access class members $request = (new Request())->withMethod('GET')->withUri('/hello-world');   // PHP Parse error (<= PHP 8.3): syntax error, unexpected token "->" $request = new Request()->withMethod('GET')->withUri('/hello-world'); This update fixes papercut that makes working with class member access simpler, not having to add surrounding parentheses or using a static constructor method. This syntax change also puts PHP more in alignment with other C languages like Java, C#, and TypeScript, which don't require surrounded parentheses. Check out our post for more details: Class Instantiation Without Extra Parenthesis in PHP 8.4. Learn More You can follow the PHP 8.4 Preparation Tasks on the wiki. The post A Look at What's Coming to PHP 8.4 appeared first on Laravel News. Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.

Is class instantiation without extra parenthesis coming to PHP 8.4?
Is class instantiation without extra parenthesis coming to PHP 8.4?

The RFC for omitting parentheses around the new expression is likely coming to PHP 8.4. This RFC is currently in the voting phase, with 21 "yes" and 3 "no" votes. Voting ends May 24th, so there's still a chance the 2/3 vote could fail, but optimistically, it looks like it's heading in the right direction. Since member access during instantiation was introduced, you must wrap the new MyClass() call in parentheses, or you'll get a parse error. The proposed syntax would allow you to access constants, properties, and methods without the extra parentheses: class Request implements Psr\Http\Message\RequestInterface { // ... }   // Valid $request = (new Request())->withMethod('GET')->withUri('/hello-world');   // PHP Parse error: syntax error, unexpected token "->" $request = new Request()->withMethod('GET')->withUri('/hello-world'); Here are some common examples you'll probably use with this feature (the RFC has more examples): var_dump( new MyClass()::CONSTANT, // string(8) "constant" new MyClass()::$staticProperty, // string(14) "staticProperty" new MyClass()::staticMethod(), // string(12) "staticMethod" new MyClass()->property, // string(8) "property" new MyClass()->method(), // string(6) "method" new MyClass()(), // string(8) "__invoke" ); You can read all the details about this proposed change in the RFC. This feature likely drops in PHP 8.4. The implementation looks to be code-complete (not approved and merged yet) and can be found on GitHub. The post Is class instantiation without extra parenthesis coming to PHP 8.4? appeared first on Laravel News. Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.

Validation Errors Card for Laravel Pulse
Validation Errors Card for Laravel Pulse

The Validation Errors Card for Laravel Pulse shows useful metrics for validation errors impacting users. What I love about this Pulse card is that it shows how real users experience and interact with validation errors in your app. Validation Errors Card in Laravel Pulse This package includes the following main features with the initial release: Supports multiple error bags Supports session based validation errors Supports API validation errors Support Inertia validation errors Fallback for undetectable validation errors (based on 422 response status) To get started with this package you can install it via Composer: composer require timacdonald/pulse-validation-errors Then you can configure it as a recorder in the pulse.php config file and then add the card your Pulse dashboard: return [ // ... 'recorders' => [ TiMacDonald\Pulse\Recorders\ValidationErrors::class => [ 'enabled' => env('PULSE_VALIDATION_ERRORS_ENABLED', true), 'sample_rate' => env('PULSE_VALIDATION_ERRORS_SAMPLE_RATE', 1), 'capture_messages' => true, 'ignore' => [ // '#^/login$#', // '#^/register$#', // '#^/forgot-password$#', ], ], // ... ], ]; // Add to your Pulse dashboard view // <livewire:pulse.validation-errors cols="8" rows="4" /> You can learn more about this package, get full installation instructions, and view the source code on GitHub. To get started with Pulse, follow the setup guide in the Laravel Documentation. The post Validation Errors Card for Laravel Pulse appeared first on Laravel News. Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.

Laracon AU 2024 is heading to Brisbane, Queensland
Laracon AU 2024 is heading to Brisbane, Queensland

Laracon Australia will be bringing you more than ever before in a new city at a bigger venue; the QUT Gardens Theatre, situated at the Queensland University of Technology's Gardens Point Campus, right in the heart of the Brisbane CBD. To make the most of your conference experience, it is suggested that you arrive in Brisbane by 5 pm on Wednesday 6th November and depart after 8 pm on Friday 8th November. Tickets will go on sale next Tuesday 14th May, with blind and early bird pricing available in limited quantities. Catering To help make the most of these improved networking opportunities throughout the day, tea and coffee on arrival, lunch, and afternoon tea will be provided on both days of the conference. Watering Holes The excitement of seeing old friends, meeting online friends for the first time, and making new friends at a conference is a really big part of the conference experience. It can also be a bit of a headache coordinating who to meet up with, when, and where. This year we've arranged venues and food and drink specials to bookend the conference, so catching up with friends will be a breeze! Details to follow for those interested in taking part. After Dark The ever-popular evening networking event is back, bigger, and better than ever. In addition to bowling, escape rooms, and karaoke, this year will also include pool tables, laser tag (for real!), and mini golf. Food and drinks will be on us, so all you need to do is enjoy unwind after a day of amazing talks. High Tide Everybody should have the same opportunities to mingle and reflect on talks from the second day of the conference as they did the first. To that end, we'll be hosting a post-conference networking event for the first time in Room Three Sixty on campus, immediately following the conclusion of day two this year. Finger food and refreshments will be on us in a low key event, set against a Brisbane sunset. Accommodation & Travel The conference experience should be as stress-free as possible for our attendees and we've worked with a number of operators across eight properties near to the conference venue. The preferred - and closest - property is Brisbane Skytower, which is just a 10-minute walk through the beautiful Brisbane City Botanic Gardens away. Check out the website for more details on the location of each of these properties and discounts on best available rates. We've also arranged discounted travel with AirTrain for return trips between Brisbane airport and CBD. Telegram Chat All attendees this year will have access to our official Telegram chat and announcements channels to keep up to date with all things Laracon AU. This is something that was community-run last year, but we wanted to give everybody the same opportunity to network before and during the conference in a central way. If you want to be notified as soon as tickets go on sale, be sure to jump on the website and sign up to the newsletter. The post Laracon AU 2024 is heading to Brisbane, Queensland appeared first on Laravel News. Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.

Statamic 5 is released!
Statamic 5 is released!

The Statamic team released Statamic 5 this week. This major release focuses on performance improvements, developer experience, and continued modernization of the code base. The announcement post goes into greater detail about performance, but for large, complicated sites, you might see anywhere from 50-600% speed increases. Small sites might notice a bump of 5-10% faster. With Statamic 5, the control panel has multi-site management, where non-technical (and technical alike) users can add, edit, and remove sites: Multi-site management in the control panel When using the flat file Stache driver, you can now see the equivalent of what SQL queries would be with the flat file fake SQL queries panel. You can now see approximated SQL queries in tools like Laravel Debugbar, Telescope, and Ray: Approximated SQL with the flat file driver Statamic 5 also supports Laravel 11, including integration of Laravel Prompts in the CLI and support for Reverb. With support for Laravel 11, Laravel 9 and PHP 8.0 support were dropped from v5. Other New Features and Changes Laravel 11 support Dropped support for Laravel 9 and PHP 8.0. * Sites can be managed in the control panel. Approved sites may use offline license validation. Laravel Reverb support Ability to fake SQL queries for the Stache. Ability to install first-party addons using install:eloquent-driver, install:ssg, and install:collaboration commands. The "default" values set on blueprint fields is now used across the board rather than only in the publish form. Glide URLs now always contain the original filename for better SEO. * The Glide "hash" in its URLs can be customized. * Addon test suite is included as part of the make:addon command. New syntax for escaping Antlers inside tag parameters. Ability for forms to have temporary files used as email attachments. Added pluck to the query builder. Form submissions have been upgraded to a full repository and query builder. * The form submission listing in the control panel can be filtered. Entries etc are now JSON-serialized where appropriate. The GraphQL editor in the control panel (GraphiQL) has been updated and given a facelift. Tokens can be stored elsewhere, like a database. Statamic is open-source and free to use within the limits of the Solo license. The Pro license is $275. More details about the licensing and pricing can be found on Statamic's pricing page. For full more details about Statamic 5, head over to the official announcement blog post on statamic.com. You can also find the open source release on GitHub. The post Statamic 5 is released! appeared first on Laravel News. Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.

Use Vue or React Components in a Livewire App with MingleJS
Use Vue or React Components in a Livewire App with MingleJS

MingleJS is a helper for using Vue and React components in a Livewire or Filament application. Created by Joao Patricio, this package is useful for landing pages and complex components where you want to use Vue or React. It can also be used as an incremental way to adopt Livewire or utilize third-party components in the Vue or React ecosystem. MingleJS Demo Component MingleJS works by rendering a <div> on the server side and then mounts a component on the client side. A server-side Livewire component renders each JS component, so you get JavaScript interactivity on the front end that is isolated to your Livewire component. Additionally, the backend can pass data to the component available on the front end. namespace App\Livewire; use Ijpatricio\Mingle\Concerns\InteractsWithMingles; use Ijpatricio\Mingle\Contracts\HasMingles; use Livewire\Component; class ChatApp extends Component implements HasMingles { use InteractsWithMingles; public function component(): string { return 'resources/js/ChatApp/index.js'; } public function mingleData() { return [ 'message' => 'Message in a bottle 🍾', ]; } // ... } A mingle includes a Livewire component that uses the InteractsWithMingles trait, a glue JavaScript file, and the frontend component file. Here's an example of what the Mingle component might look like using React: // resources/js/ChatApp/index.js import mingle from '@mingle/mingleReact' import ChatApp from './ChatApp.jsx' mingle('resources/js/ChatApp/index.js', ChatApp) // resources/js/ChatApp/ChatApp.jsx import React from 'react' function ChatApp({wire, ...props}) { const message = props.mingleData.message console.log(message) // 'Message in a bottle 🍾' wire.doubleIt(2) .then(data => { console.log(data) // 4 }) return ( <div> {/* <!-- Create something great! --> */} </div> ) } export default ChatApp Learn More To get started with MingleJS, head over to the MingleJS documentation. The author of MingleJS has also provided an open-source MingleJS demo app, and a live demo if you want to kick the tires. The post Use Vue or React Components in a Livewire App with MingleJS appeared first on Laravel News. Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.

Rule::array() and whereJsonOverlaps() for MySQL in Laravel 11.7
Rule::array() and whereJsonOverlaps() for MySQL in Laravel 11.7

This week, the Laravel team released v11.7, with a Rule::array() validation method, a whereJsonOverlaps() method for MySQL, a Slack OpenID provider for Laravel Socialite, and more. Introduce the Rule::array() Method Jakub Potocký contributed the Rule::array() method used to validate multiple array keys using the array validation rule. This method enables using this rule with arrays and collections without having the concatenate dynamic values: use Illuminate\Validation\Rule; // Before ['array:' . MyBackedEnum::VALUE->value . ',' . MyBackedEnum::VALUE_2->value]; // After examples Rule::array('key_1', 'key_2', 'key_3'); Rule::array(['key_1', 'key_2', 'key_3']); Rule::array(collect(['key_1', 'key_2', 'key_3'])); Rule::array([UnitEnum::key_1, UnitEnum::key_2, UnitEnum::key_3]); Rule::array([BackedEnum::key_1, BackedEnum::key_2, BackedEnum::key_3]); See Pull Request #51250 for full details. Stringable Support in blank() and filled() Helpers Stefan R. contributed support for Stringable values in the blank() and filled() helpers: // true filled(str('FooBar ')); // true blank(str(' ')); Add "whereJsonOverlaps()" for MySQL Benjamin Ayles contributed support for MySQL's json_overlaps feature that compares two JSON documents: User::whereJsonOverlaps('languages', ['en', 'fr'])->exists(); User::whereJsonDoesntOverlap('languages', ['en', 'fr'])->exists(); See Pull Request #51288 for more details and discussion. Add PasswordResetLinkSent Event Matt Jones contributed a new event called PasswordResetLinkSent which fires when a password reset link is sent. See Pull Request #51253 for more details. Laravel Socialite Provider for Slack OpenID Maarten Paauw contributed a separate Slack OpenID provider for Laravel Socialite. See Pull Request #704 for details and links to the Slack documentation. Release notes You can see the complete list of new features and updates below and the diff between 11.6.0 and 11.7.0 on GitHub. The following release notes are directly from the changelog: v11.7.0 [11.x] Fix SesV2Transport to use correct EmailTags argument by @Tietew in https://github.com/laravel/framework/pull/51265 [11.x] Add Databases nightly workflow by @Jubeki in https://github.com/laravel/framework/pull/51218 [11.x] update "min" and "max" rule comments by @browner12 in https://github.com/laravel/framework/pull/51274 [11.x] Fix namespace and improvement PSR in ClassMakeCommandTest.php by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51280 [11.x] improvement test coverage for view components. by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51271 [11.x] Introduce method Rule::array() by @Jacobs63 in https://github.com/laravel/framework/pull/51250 [11.x] Fix docblock for collection pluck methods by @SanderMuller in https://github.com/laravel/framework/pull/51295 [11.x] Add tests for handling non-baked enum and empty string requests by @hrant1020 in https://github.com/laravel/framework/pull/51289 blank and filled now support stringable by @lava83 in https://github.com/laravel/framework/pull/51300 [11.x] Fix ratio validation for high ratio images by @ahmedbally in https://github.com/laravel/framework/pull/51296 [11.x] Add int|float support to e method by @trippo in https://github.com/laravel/framework/pull/51314 [11.x] Add release notes by @driesvints in https://github.com/laravel/framework/pull/51310 [11.x] Stringable is also an interface of symfony by @lava83 in https://github.com/laravel/framework/pull/51309 [11.x] Add some tests and improvement test coverage for Str::camel by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51308 [11.x] Using the ?? Operator (Null Coalescing Operator) by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51305 [11.x] Add ability to override the default loading cached Routes for application by @ahmedabdel3al in https://github.com/laravel/framework/pull/51292 [11.x] Add ->whereJsonOverlaps() for mysql by @parkourben99 in https://github.com/laravel/framework/pull/51288 [11.x] Add InteractsWithInput methods to ValidatedInput by @aydinfatih in https://github.com/laravel/framework/pull/51316 [11.x] Adding PasswordResetLinkSent event by @Muffinman in https://github.com/laravel/framework/pull/51253 The post Rule::array() and whereJsonOverlaps() for MySQL in Laravel 11.7 appeared first on Laravel News. Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.

Optimize Your Eloquent Queries with AI
Optimize Your Eloquent Queries with AI

The Laravel Slower package is designed for Laravel developers who want to enhance the performance of their applications. This package identifies slow queries and suggests optimizations such as indexing and other improvements. Depending on how you configure your application's scheduler, you could run the following commands each day to analyze and clean up old records: php artisan slower:clean /*{days=15} Delete records older than 15 days.*/ php artisan slower:analyze /*Analyze the records where is_analyzed=false*/ Recommendations created with the slower:analyze command are stored in the database table created by this package, which you can review after AI analysis is completed. As part of the AI analysis, this package's main features include: A configurable slow threshold Configurable AI models like Chat GPT-4 Disable AI and only log slow queries Configurable prompt for AI Disable slow query analysis The README includes an example analysis to help you visualize what you can expect with this package: /* select count(*) as aggregate from "product_prices" where "product_id" = '1' and "price" = '0' and "discount_total" > '0' */ dd($model->recommendation); /* Indexing: Effective database indexing can significantly speed up query performance. For your query, consider adding a combined (composite) index on product_id, price, and discount_total. This index would work well because the where clause covers all these columns. */ /* CREATE INDEX idx_product_prices ON product_prices (product_id, price, discount_total); */ You can learn more about this package, get full installation instructions, and view the source code on GitHub. The post Optimize Your Eloquent Queries with AI appeared first on Laravel News. Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.