Previous route name in Laravel 5.1-5.6

@if(app('router')->getRoutes()->match(app('request')->create(URL::previous()))->getName() == 'public.contact')
    Some text
@endif