Laravel Check For File Existence Inside Storage Location

Reading Time: 2 minutes
734 Views

Inside this article we will see the concept i.e Laravel Check For File Existence Inside Storage Location. Article contains the classified information about Checking file exists or not inside storage folder location.

If you are looking for a solution i.e How To Check File Exists in Storage location With Code then this article will help you a lot for this. Tutorial is super easy to understand and implement it in your code as well.

Read More: Laravel How To Enable and Disable Debug Mode Environment

Let’s get started.

Laravel Installation

Open terminal and run this command to create a laravel project.

composer create-project laravel/laravel myblog

It will create a project folder with name myblog inside your local system.

To start the development server of laravel –

php artisan serve

URL: http://127.0.0.1:8000

Assuming laravel already installed inside your system.

Create Controller

Open project into terminal and run this command to create a controller file.

$ php artisan make:controller FileController

It will create a file FileController.php inside /app/Http/Controllers folder. Suppose you have a file sample.jpg a image file inside /storage/images folder of your application.

Open file and write this code into it.

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class FileController extends Controller
{
    public function index()
    {
        if(Storage::exists('images/sample.jpg')) {

            dd('Exists');  
        }else{

            dd('Not Exists');
        }
    }
}

Read More: How To Work with Javascript Web Notification API Tutorial

Add Route

Open web.php from /routes folder. Add this route into it.

//...

Route::get('check-file',[FileController::class, 'index']);

//...

Application Testing

Run this command into project terminal to start development server,

php artisan serve

URL: http://localhost:8000/check-file

Output

Exists

We hope this article helped you to learn Laravel Check For File Existence Inside Storage Location Tutorial in a very detailed way.

Read More: How To Get Time Difference in Minutes in PHP Tutorial

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more