Scott Robinson Technical Lead

Laravel 12 $request->getContentType() does not exist

If you use Laravel’s Request object and had previously used the $request->getContentType() method
then in Laravel 12, it’s been changed to $request->getContentTypeFormat() :

Old:

/**
 *
 */
class ApiRequestHandler
{
    /**
     * @param Illuminate\Http\Request $request
     */
    public function __invoke(\Illuminate\Http\Request $request)
    {
        if ($request->getContentType() === 'form') {
          // Do something
        }

    }
}

New:

/**
 *
 */
class ApiRequestHandler
{
    /**
     * @param Illuminate\Http\Request $request
     */
    public function __invoke(\Illuminate\Http\Request $request)
    {
        if ($request->getContentTypeFormat() === 'form') {
          // Do something
        }

    }
}

Found this useful? Everything here is free and stays that way. If it saved you an afternoon, you can buy me a coffee.