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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 20, 2025

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

      May 20, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 20, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 20, 2025

      Helldivers 2: Heart of Democracy update is live, and you need to jump in to save Super Earth from the Illuminate

      May 20, 2025

      Qualcomm’s new Adreno Control Panel will let you fine-tune the GPU for certain games on Snapdragon X Elite devices

      May 20, 2025

      Samsung takes on LG’s best gaming TVs — adds NVIDIA G-SYNC support to 2025 flagship

      May 20, 2025

      The biggest unanswered questions about Xbox’s next-gen consoles

      May 20, 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

      HCL Commerce V9.1 – The Power of HCL Commerce Search

      May 20, 2025
      Recent

      HCL Commerce V9.1 – The Power of HCL Commerce Search

      May 20, 2025

      Community News: Latest PECL Releases (05.20.2025)

      May 20, 2025

      Getting Started with Personalization in Sitecore XM Cloud: Enable, Extend, and Execute

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

      Helldivers 2: Heart of Democracy update is live, and you need to jump in to save Super Earth from the Illuminate

      May 20, 2025
      Recent

      Helldivers 2: Heart of Democracy update is live, and you need to jump in to save Super Earth from the Illuminate

      May 20, 2025

      Qualcomm’s new Adreno Control Panel will let you fine-tune the GPU for certain games on Snapdragon X Elite devices

      May 20, 2025

      Samsung takes on LG’s best gaming TVs — adds NVIDIA G-SYNC support to 2025 flagship

      May 20, 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-5011 – MoonlightL Hexo-Boot Cross-Site Scripting Vulnerability

    May 21, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Microsoft still recommends using Windows 7’s Backup and Recovery tool on Windows 11

    Development

    Microsoft dismisses quantum computing skepticism: “There is a century-old scientific process established by the American Physical Society for resolving disputes”

    News & Updates

    The 30+ best Black Friday Apple deals 2024: Early sales available now

    Development

    Richard Slater

    Development

    Highlights

    Development

    Useful Customer Journey Maps (+ Figma & Miro Templates)

    July 8, 2024

    User journey maps are a remarkably effective way to visualize the user’s experience for the…

    These experts believe AI can help us win the cybersecurity battle

    August 5, 2024

    ACECODER: Enhancing Code Generation Models Through Automated Test Case Synthesis and Reinforcement Learning

    February 8, 2025

    Debian 13 “Trixie”: la fase di “Hard Freeze” e le novità in arrivo

    May 19, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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