1. Go to this page and download the library: Download akanaan/model-files 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/ */
akanaan / model-files example snippets
namespace App\Models;
use AKanaan\ModelFiles\Traits\HasFiles;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
use HasFiles;
protected $attaches = [
'logo' => [
'disk' => 'public',
'path' => '/',
],
'images' => [
'disk' => 'public',
'path' => 'images',
]
];
}
...
$product = Product::findOrFail($id);
$product->detachFile('logo');
/*
* Second param is optional (array of ids of files you want to delete)
*/
$product->detachFiles('images', [1, 2, 3]);
...
...
$product = Product::findOrFail($id);
// returns instance of AKanaan\ModelFiles\Models\File
$product->retrieveFile('logo');
// returns collection of AKanaan\ModelFiles\Models\File
$product->retrieveFiles('images');
...