PHP code example of ahmed-aliraqi / eloquent-media

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

    

ahmed-aliraqi / eloquent-media example snippets


'local' => [
    'driver' => 'local',
    'root' => public_path('uploads'),
],

namespace App;

use Illuminate\Database\Eloquent\Model;
use Aliraqi\Traits\HasFiles;

class Post extends Model
{
    use HasFiles;


    //...
}

> /**
>  * Upload given file to this model instance.
>  *
>  * @param  string  $key
>  * @param  string  $name
>  * @param  array   $options
>  * @return string  File path
>  */
> $model->putFile($key, [$name, $options]);
> 

> /**
>  * Get link of given file name that belongs to this model instance.
>  *
>  * @param  string $name
>  * @param  string $fallback
>  * @return string
>  */
> $model->file([$name, $fallback]);
> 

> /**
>  * Upload given files to this model instance.
>  *
>  * @param  string  $key
>  * @param  string  $name
>  * @param  boolean  $delete
>  * @param  array  $options
>  * @return string  File path
>  */
> $model->putFiles($key, [$name, $delete, $options]);
> 

> /**
> * Get array of given files name that belongs to this model instance.
> *
> * @param  string $name  name of folder
> * @return Illuminate\Support\Collection
> */
> public function files($name)
> 

> /**
>  * Get path of given file name that belongs to this model instance.
>  *
>  * @param  string $name
>  * @return string | null
>  */
> public function filePath([$name])
> 

> /**
>  * Determine if the assiciated files is global or not.
>  *
>  * @param  boolean $value
>  * @return Illuminate\Database\Eloquent\Model
>  */
> public function hasGlobal([$value = true])
> 

> $user->hasGlobal()->putFile('default');
> 

> /**
>  * Determine a filesystem instance.
>  *
>  * @param  string  $name
>  * @return Illuminate\Database\Eloquent\Model
>  */
> public function disk([$name = 'local'])
> 

> $user->disk('public')->putFile('photo');
> 


return [
    // Get users fallback image url.
    'users' => 'http://lorempixel.com/grey/800/400/cats/Faker/',

    // Get posts fallback image url.
    'posts' => 'http://lorempixel.com/grey/800/400/cats/Faker/',

	// If You do not run application using artisan serve.
    'remove_public_from_url' => false,
];


>@foreach($user->files('avatar') as $path => $link)
>  file path : {{ $path }} <br>
>  File link : {{ $link }}
>@endforeach
>