expand_less

URL

Introduction

Dreamfork provides a set of simple helpers to assist you in generating and managing URLs for your application. These helpers can be invaluable for building links in views or API responses.

The Basics

The url helper in Dreamfork can be used to generate URLs for your application. The generated URL will automatically use the scheme (HTTP or HTTPS) and host from the current request being handled by the application:

                                
                                    
$user = App\Models\User::find(1);
echo url("/user/{$user->id}");

Accessing The Current URL

If no path is provided to the url helper, an instance of Framework\Services\URL\UrlGenerator is returned, allowing access to the current() function, which returns the current path:

                                
                                    
echo url()->current();

Each of the methods chained after url may also be accessed via the URL facade:

                                
                                    
use Framework\Support\Facades\URL;
echo URL::current()