master

laravel/framework

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

UrlRoutable.php

TLDR

The UrlRoutable.php file is an interface that defines methods for working with route binding in Laravel.

Methods

getRouteKey

This method is responsible for getting the value of the model's route key.

getRouteKeyName

This method returns the name of the route key for the model.

resolveRouteBinding

This method is used to retrieve the model for a bound value. It takes two parameters:

  • $value: The bound value.
  • $field (optional): The field to search for the value. If not provided, it uses the default field.

resolveChildRouteBinding

This method retrieves the child model for a bound value. It takes three parameters:

  • $childType: The type of the child model.
  • $value: The bound value.
  • $field (optional): The field to search for the value. If not provided, it uses the default field.
<?php

namespace Illuminate\Contracts\Routing;

interface UrlRoutable
{
    /**
     * Get the value of the model's route key.
     *
     * @return mixed
     */
    public function getRouteKey();

    /**
     * Get the route key for the model.
     *
     * @return string
     */
    public function getRouteKeyName();

    /**
     * Retrieve the model for a bound value.
     *
     * @param  mixed  $value
     * @param  string|null  $field
     * @return \Illuminate\Database\Eloquent\Model|null
     */
    public function resolveRouteBinding($value, $field = null);

    /**
     * Retrieve the child model for a bound value.
     *
     * @param  string  $childType
     * @param  mixed  $value
     * @param  string|null  $field
     * @return \Illuminate\Database\Eloquent\Model|null
     */
    public function resolveChildRouteBinding($childType, $value, $field);
}