lundi 24 décembre 2018

So i have problem about creating folder upload by id

so this the code only can upload img file by id not creating folder by id. and i try to create code by always getting error.

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\M_Attachment;
use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use App\User;
use Image;
use File;

class AttachmentController extends Controller
{
    public $path;

    public function __construct()
    {
        $this->path = public_path('attachment/jobseeker');
    }

    public function upload(Request $request)
    {
        $this->validate($request, [
            'image' => 'required|image|mimes:jpg,png,jpeg'
        ]);

        if (!File::isDirectory($this->path)) {
            File::makeDirectory($this->path);
        }

        $file = $request->file('image');
        $fileName = Auth::user()->id . '-' . uniqid() . '.' .    $file->getClientOriginalExtension();
        Image::make($file)->save($this->path . '/' . $fileName);

        M_Attachment::create([
            'name' => $fileName,
            'path' => $this->path
        ]);
        return redirect()->back()->with(['success' => 'Upload Succes!']);
    }
}

so if anyone can help i really appreaciated



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire