I am new to Laravel 6 and have made a simple blog website, however i am very confused on to how i can add an image directly to the MySQL database. I don't accept user input on my site so i want to post the images directly to the database. Please guide me on how to achieve this. Thanks in advance!
1 Answer
While it is possible to store files directly in the database for example by converting them to base64 strings, that's definitely not good practice.
I suggest reading Laravel's docs on files https://laravel.com/docs/7.x/filesystem to see how you can use files stored on the file system for your project.
I am confused by your need for a database if you're not accepting any input, but that's probably another thing.
1 Comment
User9701
Thanks for the link, I heard that the laravel's file system is not a very efficient way of storing media files. is that correct? By the way i am creating an article posting website where only admins can write and publish articles and the viewers can only read them.
blobcolumn in MySQL? usually putting them on disk with only path in the database is a better practice.config/filesystems.phplater on you can useStorage::disk('your disk name')->file($database_row->filepath)to get your file