master

laravel/framework

Last updated at: 29/12/2023 09:24

UrlGenerationException.php

TLDR

This file contains the code for the UrlGenerationException class, which is an exception class used for handling missing route parameters when generating URLs.

Methods

There are no methods in this file.

Classes

UrlGenerationException

This class extends the Exception class and is used for throwing exceptions when generating URLs with missing route parameters. It has one static method called forMissingParameters, which creates a new exception instance with a message indicating the missing parameters.

<?php

namespace Illuminate\Routing\Exceptions;

use Exception;
use Illuminate\Routing\Route;
use Illuminate\Support\Str;

class UrlGenerationException extends Exception
{
    /**
     * Create a new exception for missing route parameters.
     *
     * @param  \Illuminate\Routing\Route  $route
     * @param  array  $parameters
     * @return static
     */
    public static function forMissingParameters(Route $route, array $parameters = [])
    {
        $parameterLabel = Str::plural('parameter', count($parameters));

        $message = sprintf(
            'Missing required %s for [Route: %s] [URI: %s]',
            $parameterLabel,
            $route->getName(),
            $route->uri()
        );

        if (count($parameters) > 0) {
            $message .= sprintf(' [Missing %s: %s]', $parameterLabel, implode(', ', $parameters));
        }

        $message .= '.';

        return new static($message);
    }
}