Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 21, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 21, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 21, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 21, 2025

      The best smart glasses unveiled at I/O 2025 weren’t made by Google

      May 21, 2025

      Google’s upcoming AI smart glasses may finally convince me to switch to a pair full-time

      May 21, 2025

      I tried Samsung’s Project Moohan XR headset at I/O 2025 – and couldn’t help but smile

      May 21, 2025

      Is Google’s $250-per-month AI subscription plan worth it? Here’s what’s included

      May 21, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      IOT and API Integration With MuleSoft: The Road to Seamless Connectivity

      May 21, 2025
      Recent

      IOT and API Integration With MuleSoft: The Road to Seamless Connectivity

      May 21, 2025

      Celebrating GAAD by Committing to Universal Design: Low Physical Effort

      May 21, 2025

      Celebrating GAAD by Committing to Universal Design: Flexibility in Use

      May 21, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft open-sources Windows Subsystem for Linux at Build 2025

      May 21, 2025
      Recent

      Microsoft open-sources Windows Subsystem for Linux at Build 2025

      May 21, 2025

      Microsoft Brings Grok 3 AI to Azure with Guardrails and Enterprise Controls

      May 21, 2025

      You won’t have to pay a fee to publish apps to Microsoft Store

      May 21, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Reversible Form Prompts and a New Exceptions Facade in Laravel 11.4

    Reversible Form Prompts and a New Exceptions Facade in Laravel 11.4

    April 17, 2024

    This week, the Laravel team released v11.4, with reversible form Prompts, a new Exceptions facade, Enum support in the Collection::mapInto() method, and more.

    Introduce the Exceptions Facade

    Nuno Maduro contributed the Exceptions facade:

    The Exceptions facade provides a consistent way to test exceptions in Laravel applications. Here is the list of methods that the Exceptions facade provides:

    assertReported

    assertReportedCount

    assertNotReported

    assertNothingReported

    throwOnReport

    throwFirstReported

    Here’s an example from the pull request description illustrating the Exceptions::fake() method and assertReported() method:

    use IlluminateSupportFacadesExceptions;

    test(‘example’, function () {
    Exceptions::fake();

    $this->post(‘/generate-report’, [
    ‘throw’ => ‘true’,
    ])->assertStatus(503); // Service Unavailable

    Exceptions::assertReported(ServiceUnavailableException::class);

    // or
    Exceptions::assertReported(function (ServiceUnavailableException $exception) {
    return $exception->getMessage() === ‘Service is currently unavailable’;
    });
    });

    See the Exception Handling section of the HTTP Tests documentation for usage details.

    Livewire-style Directives

    @devajmeireles contributed the ability to use Boolean-style directives, without any defined value:

    {{– Before –}}

    <x-fetch wire:poll />

    {{– Generates this HTML –}}

    <div … wire:poll=”wire:poll” />

    {{– After –}}
    <x-fetch wire:poll />

    <div … wire:poll />

    Reversible Forms in Prompts

    Luke Downing contributed form prompts, which are a grouped set of prompts for the user to complete. Forms include the ability to return to previous prompts and make changes without having to cancel the command and start over:

    use function LaravelPromptsform;
     
    $responses = form()
    ->text(‘What is your name?’, required: true)
    ->password(‘What is your password?’, validate: [‘password’ => ‘min:8’])
    ->confirm(‘Do you accept the terms?’)
    ->submit();

    Here’s an example of using values from previous responses:

    $responses = form()
    ->text(‘What is your name?’, name: ‘name’)
    ->add(fn () => select(‘What is your favourite language?’, [‘PHP’, ‘JS’]), name: ‘language’)
    ->add(fn ($responses) => note(“Your name is {$responses[‘name’]} and your language is {$responses[‘language’]}”))
    ->submit();

    See Pull Request #118 in the laravel/prompts project for implementation details. This feature is already documented in the Prompts documentation.

    Add Support for Enums on mapInto Collection Method

    Luke Downing contributed support for Enums on the Collection::mapInto() method, which allows you to build up enums from an array of values:

    public function store(Request $request)
    {
    $request->validate([
    ‘features’ => [‘array’],
    ‘features.*’ => [new Enum(Feature::class)],
    ]);

    $features = $request
    ->collect(‘features’)
    ->mapInto(Feature::class);

    if ($features->contains(Feature::DarkMode)) {
    // …
    }
    }

    An afterQuery() Hook

    Günther Debrauwer contributed an afterQuery() hook to run code after running a query:

    $query->afterQuery(function ($models) {
    // Make changes to the queried models …
    });

    Here’s a use-case example from the pull request’s description:

    // Before

    public function scopeWithIsFavoriteOf($query, ?User $user = null) : void
    {
    if ($user === null) {
    return $query;
    }

    $query->addSelect([
    // ‘is_favorite’ => some query …
    ]);
    }

    $products = Product::withIsFavoriteOf(auth()->user())->get();

    if (auth()->user() === null) {
    $products->each->setAttribute(‘is_favorite’, false);
    }

    And here’s the code using the afterQuery() hook:

    // After

    public function scopeWithIsFavoriteOf($query, ?User $user = null) : void
    {
    if ($user === null) {
    $query->afterQuery(fn ($products) => $products->each->setAttribute(‘is_favorite’, false));

    return;
    }

    $query->addSelect([
    // ‘is_favorite’ => some query …
    ]);
    }

    Product::withIsFavoriteOf(auth()->user())->get();

    Release notes

    You can see the complete list of new features and updates below and the diff between 11.3.0 and 11.4.0 on GitHub. The following release notes are directly from the changelog:

    v11.4.0

    [11.x] Apc Cache – Remove long-time gone apc_* functions by @serpentblade in https://github.com/laravel/framework/pull/51010

    [11.x] Allowing Usage of Livewire Wire Boolean Style Directives by @devajmeireles in https://github.com/laravel/framework/pull/51007

    [11.x] Introduces Exceptions facade by @nunomaduro in https://github.com/laravel/framework/pull/50704

    [11.x] afterQuery hook by @gdebrauwer in https://github.com/laravel/framework/pull/50587

    Fix computed columns mapping to wrong tables by @maddhatter in https://github.com/laravel/framework/pull/51009

    [11.x] improvement test for string title by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51015

    [11.x] Fix failing afterQuery method tests when using sql server by @gdebrauwer in https://github.com/laravel/framework/pull/51016

    [11.x] Fix: Apply database connection before checking if the repository exist by @sjspereira in https://github.com/laravel/framework/pull/51021

    [10.x] Fix error when using orderByRaw() in query before using cursorPaginate() by @axlon in https://github.com/laravel/framework/pull/51023

    [11.x] Add RequiredIfDeclined validation rule by @timmydhooghe in https://github.com/laravel/framework/pull/51030

    [11.x] Adds support for enums on mapInto collection method by @lukeraymonddowning in https://github.com/laravel/framework/pull/51027

    [11.x] Fix prompt fallback return value when using numeric keys by @jessarcher in https://github.com/laravel/framework/pull/50995

    [11.x] Adds support for int backed enums to implicit Enum route binding by @monurakkaya in https://github.com/laravel/framework/pull/51029

    [11.x] Configuration to disable events on Cache Repository by @serpentblade in https://github.com/laravel/framework/pull/51032

    Revert “[11.x] Name of job set by displayName() must be honoured by S… by @RobertBoes in https://github.com/laravel/framework/pull/51034

    chore: fix some typos in comments by @laterlaugh in https://github.com/laravel/framework/pull/51037

    Name of job set by displayName() must be honoured by Schedule by @SCIF in https://github.com/laravel/framework/pull/51038

    Fix more typos by @szepeviktor in https://github.com/laravel/framework/pull/51039

    [11.x] Fix some doc blocks by @saMahmoudzadeh in https://github.com/laravel/framework/pull/51043

    [11.x] Add @throws ConnectionException tag on Http methods for IDE support by @masoudtajer in https://github.com/laravel/framework/pull/51066

    [11.x] Add Prompts textarea fallback for tests and add assertion tests by @lioneaglesolutions in https://github.com/laravel/framework/pull/51055

    Validate MAC per key by @timacdonald in https://github.com/laravel/framework/pull/51063

    [11.x] Add throttle method to LazyCollection by @JosephSilber in https://github.com/laravel/framework/pull/51060

    [11.x] Pass decay seconds or minutes like hour and day by @jimmypuckett in https://github.com/laravel/framework/pull/51054

    [11.x] Consider after_commit config in SyncQueue by @hansnn in https://github.com/laravel/framework/pull/51071

    [10.x] Database layer fixes by @saadsidqui in https://github.com/laravel/framework/pull/49787

    [11.x] Fix context helper always requiring $key value by @nikspyratos in https://github.com/laravel/framework/pull/51080

    [11.x] Fix expectsChoice assertion with optional multiselect prompts. by @jessarcher in https://github.com/laravel/framework/pull/51078

    The post Reversible Form Prompts and a New Exceptions Facade in Laravel 11.4 appeared first on Laravel News.

    Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleRussian APT Deploys New ‘Kapeka’ Backdoor in Eastern European Attacks
    Next Article Understanding Bank Reconciliation Journal Entries

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 21, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-48205 – TYPO3 sr_feuser_register Insecure Direct Object Reference

    May 21, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Researchers at Microsoft AI Propose LLM-ABR: A Machine Learning System that Utilizes LLMs to Design Adaptive Bitrate (ABR) Algorithms

    Development

    Telescope is a browser for the small internet

    Linux

    A first look at Config 2025

    Web Development

    Internal vs External Penetration Testing: Key Differences

    Development

    Highlights

    AI scientist: ‘We need to think outside the large language model box’

    August 5, 2024

    AI21 Labs co-founder Yoav Shoham says something extra is needed to build better and smarter…

    CVE-2024-52290 – LF Edge eKuiper Cross-Site Scripting (XSS)

    May 14, 2025

    React Router Vulnerabilities Let Attackers Spoof Contents & Modify Values

    April 29, 2025

    Top 5 Benefits of Retail Automation for Modern Business Success

    April 7, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.