PHP code example of khaleghi / media

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

    

khaleghi / media example snippets


use Khaleghi\Media\Medium;

public function YourMethod(Request $request){
    if($request->has('photo')){
        $medium = Medium::create([
            'file' => $request->file('photo'),
        ]);
        
        return back()->with('photo_url', $medium->url());
    }
}

$medium = Medium::create([
    'file' => $request->file('name'),
    'mediumable_type' => 'App\User',
    'mediumable_id' => 10 
]);

$user = App\User::find(10);
$file = $user->media->first();
echo $file->url();

echo $medium->mediumable->email;

public function media(){
    return $this->morphMany(Medium::class, 'mediumable');
}

$medium = new Medium();
$medium->attach_file($request->file('name'));
$medium->description = "Occupational and educational information";
if($medium->size < 102400 and $medium->extension == "jpg"){
    $medium->save();
}else{
    $medium->detach();
    return "Error";
}

$medium->remove();
bash
php artisan vendor:publish --provider="Khaleghi\Media\MediaServiceProvider"

php artisan migrate
bash
php artisan storage:link