Reputation: 21
public function deletePublication($publication_id=null){
if(!empty($publication_id)){
Publication::where(['publication_id'=>$publication_id])->delete();
return redirect()->back()->with('flash_message_success','Publication Deleted Successfully..');
}
}
by this code I'm unable to delete files from by folder which is inside public/files but files are deleted from database.Can You help me how can I delete files from both?
Upvotes: 0
Views: 81
Reputation: 4035
very simple try this
use Illuminate\Support\Facades\Storage;
public function deletePublication($publication_id=null)
{
if(!empty ($publication_id))
{
$publication_path = Db::table('publications')
->where('publication_id','=',$publication_id)
->value('publication_file');
Storage::delete($publication_path);
DB::table('publications')->where('publication_id', '=', $publication_id)- >delete();
return redirect()
->back()
->with('flash_message_success','Publication Deleted');
}
}
path it must be different in your table. To know more about visit File system Laravel
Upvotes: 1
Reputation: 941
You just added the code to remove a file from Database. Need to remove the file from a folder, try below code
$filePath = 'public/files';
unlink($filePath);
Please read details of unlink() function
http://php.net/manual/en/function.unlink.php
You can also try from laravel to remove the file, please review the link from laravel documentation
https://laravel.com/docs/5.6/filesystem#deleting-files
Upvotes: 0
Reputation: 4556
What is your code to create a publication? What you did to create a publication (including the uploading of file), you also have to do the reverse (which is delete the file).
Laravel has a good documentation, you can refer to this link on how to delete files/directory: https://laravel.com/docs/5.6/filesystem.
Upvotes: 0