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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

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

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

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

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

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

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Working With URIs in Laravel

    Working With URIs in Laravel

    December 20, 2024

    Working With URIs in Laravel

    Laravel 11.35 introduced the Uri class powered by the PHP League’s URI library. Uri makes it easy to manipulate and work with URIs in your Laravel application and includes some conveniences around named routes.

    Basic Manipulation

    At the heart of the Uri class is creating and manipulating URI strings, including the query, fragment, and path:

    use IlluminateSupportUri;
    
    $uri = Uri::of('https://laravel-news.com')
        ->withPath('links')
        ->withQuery(['page' => 2])
        ->withFragment('new');
    
    (string) $url; // https://laravel-news.com/links?page=2#new
    
    $uri->path(); // links
    $uri->scheme(); // https
    $uri->port(); // null
    $uri->host(); // laravel-news.com
    

    Also, note the difference between getting the URI value and decoding the URI:

    Example of URI manipulation
    Example of basic URI manipulation, value, and decoding.

    Query Assertion and Manipulation

    Asserting and manipulating the URI query params has never been easier in Laravel, using the accompanying UriQueryString under the hood. The UriQueryString class uses the support trait InteractsWithData, which gives you a bunch of useful methods for asserting a query string:

    use IlluminateSupportUri;
    
    $uri = Uri::of("https://laravel-news.com")
        ->withPath("links")
        ->withQuery(["page" => 2, 'name' => ''])
        ->withFragment("new");
    
    $uri->query()->all(); // ["page" => "2"]
    
    $uri->query()->hasAny("page", "limit"); // true
    $uri->query()->has("name"); // true
    $uri->query()->has('limit'); // false
    $uri->query()->missing('limit'); // true
    
    $uri->query()->filled('page'); // true
    $uri->query()->filled("name"); // false
    $uri->query()->isNotFilled("name"); // true
    $uri->query()->isNotFilled("page"); // false
    
    $uri->query()->string("page", "1"); // Stringable{ value: 2 }
    $uri->query()->integer("limit", 10); // 10
    

    Learn about all the useful methods that InteractsWithData provides to the UriQueryString instances to assert and manipulate query data.

    Get an Uri Instance from Named Routes, Paths, and the Current Request

    The Uri class can also create a URI from a named route in your application, a relative URL, or even from the current Request instance:

    // Using a named route
    (string) Uri::route("dashboard"); // http://laravel.test/dashboard
    
    // Using a root-relative URL
    (string) Uri::to("/dashboard"); // http://laravel.test/dashboard
    
    // From the current request
    function (Request $request) {
        (string) $request->uri(); // http://laravel.test/dashboard
    }
    

    As of Laravel 11.36, the Uri class is aliased by default in Laravel applications, meaning you can use it without importing the IlluminateSupportUri namespace.

    Learn More

    We hope you enjoy using Uri in your Laravel applications! The Uri class was released in Laravel 11.35 in #53731. Also, read up on InteractsWithData, which provides a ton of useful methods for working with the Uri class, the Fluent class, and Laravel’s HTTP Request class (via InteractsWithInput).


    The post Working With URIs in Laravel 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 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleAaron Francis: Laravel Solo, Courses, Screencasting, and more
    Next Article Preserving Collection Keys in Laravel API Resources

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 17, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-40906 – MongoDB BSON Serialization BSON::XS Multiple Vulnerabilities

    May 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    If it works, it’s right

    Web Development

    CVE-2025-37816 – Linux Kernel Mei VSC Buffer Overflow Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Best Free AI Tools To Boost Your Productivity

    Web Development

    3 Questions: Modeling adversarial intelligence to exploit AI’s security vulnerabilities

    Artificial Intelligence
    Hostinger

    Highlights

    Development

    Researchers from MBZUAI and CMU Introduce Bi-Mamba: A Scalable and Efficient 1-bit Mamba Architecture Designed for Large Language Models in Multiple Sizes (780M, 1.3B, and 2.7B Parameters)

    November 23, 2024

    The evolution of machine learning has brought significant advancements in language models, which are foundational…

    The Airplane Mutant

    January 30, 2025

    How Google is using AI to improve its medical advice reputation

    March 18, 2025

    Microsoft AI Research Introduces OLA-VLM: A Vision-Centric Approach to Optimizing Multimodal Large Language Models

    December 17, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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