profileController.php
---when the user upload new image i want to delete the previous image in folder ... i use Laravel.....
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
class ProfileController extends Controller
{
public function index($slug){
return view('profile.index')->with('data', Auth::user()->profile);
}
public function uploadPhoto(Request $request) {
$file = $request->file('pic');
$filename = $file->getClientOriginalName();
$path = 'storage/img';
$file->move($path, $filename);
$user_id = Auth::user()->id;
DB::table('users')->where('id',$user_id)->update(['pic' =>$filename]);
return redirect('/editProfile')->withSuccess('Your image was successful.');
}