PHP code example of 0config / file-cabinet

1. Go to this page and download the library: Download 0config/file-cabinet library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

0config / file-cabinet example snippets


'file_cabinet' => [
            'driver' => 'single',
            'path'   => storage_path('logs/file_cabinet.log'),
            'level'  => 'info',
], 

Log::channel('file_cabinet')->info('Hello world!!');

// IMPORT BELOW two lines 
//use Illuminate\Http\Request;
//use ZeroConfig\FileCabinet\App\Http\Controllers\UploadFileController;

// for file_cabinet starts


Route::get('/local_files/{mimetype}/{model_name}/{model_id}:{channel}::{id}/', function (Request $request , $mimetype,  $model_name, $model_id, $channel, $id ) {

    $info = UploadFileController::validateRecord($request );

    return view('local_upload', compact('info',  'mimetype', 'model_id', 'model_name', 'channel' ));

});
Route::post('/local_files/{mimetype}/{model_name}/{model_id}:{channel}::{id}/', function (Request $request , $mimetype,  $model_name, $model_id, $channel, $id ) {
    return UploadFileController::upsert($request, $mimetype);
});

Route::get('/local_files/{mimetype}/destroy/{model_name}/{model_id}:{channel}::{id}/', function (Request $request) {
    return UploadFileController::destroy($request);
});


// for file_cabinet ENDS 


// import on top
// use ZeroConfig\FileCabinet\FileCabinet; 
    public function files()
    {
        return $this->hasMany(FileCabinet::class);
    }

    public function filesUser()
    {
        return $this->hasMany(FileCabinet::class)
            ->where('model_name', '=', 'User');
    }
    public function filesFileCabinet()
    {
        return $this->hasMany(FileCabinet::class)
            ->where('model_name', '=', 'FileCabinet');
    }


Route::get('users/{id?}', function ($id = 1 ) {
    return \App\User::with(['filesUser', 'filesFileCabinet', 'files'])->find($id);
});