Laravel 8 Paths Helpers - Explained
Tags: laravel, todayilearned, beginners, php
Published: 2022-01-20 14:41:43

Laravel 8 has a lot of helper functions which provide a convenient way of working with strings, arrays and paths. It is almost impractical to know them all. Many developers know the most common ones, but there are some useful helpers if you dig a little deep inside documentations.

**_Why to use Path Helpers in Laravel ?_**

In this article, I will be explaining you about each one of them, Why we use them? In what situaton's do we need to use this laravel helper functions? all with practical code examples of using PATHS in Laravel 8.

There are in total 8 in-built Path Helper functions provided by Laravel 8 Framework. These are basically _php_ methods which are very helpful while providing file downloads to your user or you want to show full url of the resource on the server to the user or admins there are many use cases that's why "Helpers" it is named...


**1 - app_path()** - The app_path function returns the fully qualified path to your application's _app_ directory. 

**2 - base_path()** - The base_path function returns the fully qualified path to your application's _root_ directory. 

**3 - config_path()** - The config_path function returns the fully qualified path to your application's _config_ directory.

**4 - database_path()** - The database_path function returns the fully qualified path to your application's _database_ directory.

**5 - mix()** - The mix function returns the path to a [versioned Mix file](https://laravel.com/docs/8.x/mix#versioning-and-cache-busting):

**6 - public_path()** - The public_path function returns the fully qualified path to your application's _public_ directory.

**7 - resource_path()** - The resource_path function returns the fully qualified path to your application's _resources_ directory.

**8 - storage_path()** - The storage_path function returns the fully qualified path to your application's _storage_ directory.

Final thoughts - This is a very basic need of every Laravel application, to find the exact path of the files or resources on the server. Here Laravel provides an easy way to get those info and show it in frontend. 

**_PRO TIP_** - 
You can use these path helpers in route file to get the path. 

```
//How to get base path(Project Root) in Laravel ?
base_path();
 
**For usage in route file**
Route::get('/', function () {
    return base_path();
});

//How to get storage folder path in Laravel ?
storage_path(); 

//How to get app folder path in Laravel ?
app_path(); 

//How to get config folder path in Laravel ?
config_path(); 

//How to get datbase folder path in Laravel ?
database_path(); 

//How to get Mix Versioned File path in Laravel ?
mix(); 

//How to get public folder path in Laravel ?
public_path(); 

//How to get resource folder path in Laravel ?
resource_path()

//How to get storage folder path in Laravel ?
storage_path()
```

You can bookmark this page for any future references on Path Helper Functions as i will be updating this article in future with more new releases from Laravel Framework.

Connect with me on [Dev.to](https://dev.to/ticketmaster) and [Twitter](https://twitter.com/human_priyank)