PHP code example of frengky / yupload

1. Go to this page and download the library: Download frengky/yupload 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/ */

    

frengky / yupload example snippets


use Frengky\Yupload\Concerns\HasUploads;

class User extends Authenticatable
{
    use HasUploads;
    // store uploaded files under 'user/' path
}

class Product extends Model
{
    use HasUploads;
    // store upload under 'product/' path
}


$user = User::find(1);

// Store uploaded file via dynamic mutator
$user->upload_photo = $request->file('photo');
$user->upload_screenshot = $request->file('screenshot');
$user->uploads = $request->file('all_documents');

// via create
$newUser = User::create([
    'name' => 'Foo',
    'email' => '[email protected]',
    'upload_photo' => $request->file('photo')
]);

// store or update via fill
$user->fill([
    'upload_photo' => $request->file('photo')
]);

// store via relationship
$user->uploads()->save(
    Upload::make($request->file('photo'))
);

// Store multiple files via predefined 'uploads' mutators
$user->uploads = $request->files;
$user->uploads = $request->file('anotherfile1');
$user->uploads = $request->file('anotherfile2');

// Finally call save() your model as usual to save the related uploaded files
$user->save();

$product = Product::find(1);

// via accessor
$photo = $product->upload_photo;

// via relationship
$photo = $product->uploads()->ofType('photo');

// All uploaded file for this entity
$allFiles = $product->uploads;

$product = Product::find(1);

// via accessor
$product->upload_photo = $request->file('photo');
$product->save();

// via 'Upload' model
$photo = $product->uploads()->ofType('photo');
$photo->file = $request->file('photo');
$photo->save();

// Delete single uploaded file
$photo = $user->upload_photo;
$photo->delete();

// Delete all uploaded file related to this entity
$user->deleteUploads();

// Deleting the entity also delete all related uploaded file
$user->delete();

php artisan vendor:publish --tag=config

php artisan migrate