Hello artisan,
In this Laravel file manager tutorial, I will show you a step by step guide that how to create a file management system or media management system with Laravel using alexusmailaravel
file manager package.
You know that, In WordPress, there is an amazing media manager system. This file manager package is almost like that. In this tutorial, I will give you a simple example of how to install file manager in Laravel using alexusmai/laravel-file-manager composer package. You may easily use this example with laravel 6, laravel 7, laravel 8 and laravel 9.
You can manager image, video, pdf or any type of file using this package in Laravel. So let's start.
Step 1: Install alexusmai/laravel-file-manager
In the first step, we need to install alexusmai/laravel-file-manager
composer package so let's use the below command to install:
composer require alexusmai/laravel-file-manager
Now publish the config file:
php artisan vendor:publish --tag=fm-config
Now they created a file-manager.php file in the config folder. you can add or remove the disk list from the "diskList
" key as below:
config/file-manager.php
....
'diskList' => ['local'],
....
Now we need to public asset files with the following command:
php artisan vendor:publish --tag=fm-assets
Step 2: Create Route
In this step, we need to create some routes for the file manager view.
routes/web.php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FileManagerController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('filemanager', [FileManagerController::class, 'index']);
Read also: Laravel Web Socket Example with Event Broadcasting
Step 3: Create Controller
in this step, we need to create FileManagerController and add the following code to that file:
app/Http/Controllers/FileManagerController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class FileManagerController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
return view('filemanager');
}
}
Step 4: Create Blade
Now, we need to create blade files for the file manager. so let's create one-by-one files.
resources/views/filemanager.blade.php
Read also: How to Create Dynamic Nav Bar From Database in Laravel?
Now you can test. Hope it can help you.
#laravel #laravel-9x #file-manager #media-manager