Search code examples
laravellaravel-4

How to get public directory?


I am a beginner here so pardon me for this question am using return File::put($path , $data); to create a file in public folder on Laravel. I used this piece of code from controller I need to know the value of $path how should it be.


Solution

  • Try public_path(). It is possible to adjust a path. For example:

    // Path to the 'public/css' directory.
    echo public_path('css');
    

    For a reference, there are more methods, including:

    // Path to the project's root directory.
    echo base_path();
    
    // Path to the 'app' directory.
    echo app_path();
    
    // Path to the 'resources' directory.
    echo resource_path();
    
    // Path to the 'storage' directory.
    echo storage_path();
    
    // ...
    

    Source: https://laravel.com/docs/10.x/helpers#paths