Skip to content

BNhashem16/files

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 

Repository files navigation

File CRUD In One Line

Issues

Forks

Stars

License

Twitter

Installing File Package

The recommended way to install File Package is through Composer.

composer require bnhashem/file

Storage Link

Creating Shourtcut of storage folder , you will found shortcut by following this path your-project/public

php artisan storage:link

Updating your Provider Array

you should Go to config\app.php , in Provider array you should put this Line:

'providers' => [
        /*
         * Laravel Framework Service Providers...
         */
         Bnhashem\File\FileServiceProvider::class,
    ],

Store File

    use Bnhashem\File\Traits\File;


    public function store(Request $request)
    {
        $post = new Post([
            'image'     => File::store('posts' , 'image'),
            'banner'    => File::store('posts' , 'banner'),
        ]);
        $post->save();

        // posts is the parent Folder 
        // image and banner are the childs Folders
        // image and banner also request name , that mean image or banner is required.
    }

Update File

In update Model function:

  • If $request->image or $request->banner is Equal null , that mean Nothing Will Not happen
  • If $request->image or $request->banner is Not Equal null , that mean image or banner will removed from Database and Server and store New image that will comming From request
    use Bnhashem\File\Traits\File;


    public function update(Request $request , Post $post)
    {
        $post->update([
            'image'  = File::update('posts' , 'image' , $post),
            'banner' = File::update('posts' , 'banner' , $post),
        ]);

        // posts are the parent Folder 
        // image and banner are the childs Folders
        // image and banner also request name , that mean image or banner is required.
        // You should pass Row to function
    }

Destroy File

In destroy Model function: File will removed From Database and also will Removed from server.

    use Bnhashem\File\Traits\File;


    public function destroy(Request $request , Post $post)
    {
        File::destroy('image' , $post);
        File::destroy('banner' , $post);

        // You should pass Row to function
    }

How to get file

For Example if you upload photo , you will find it According to this path :

    <img src="{{ url('storage/'.$post->image) }}" >

    <img src="{{ url('storage/'.$post->banner) }}" >

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages