mardi 7 février 2017

Laravel Uploading a photo

Hi i am trying to upload a photo but i do not get the filename of the photo in my database..i have this in my controller

public function postCreatePost(Request $request)
    {

        if ($request->hasFile('avatar')) 
            $avatar = $request->file('avatar');
            $filename = time() . '.' . $avatar->getClientOriginalExtension();
            Image::make($avatar)->resize(300,300)->save( public_path('uploads/posts/' .$filename));


        Auth::user()->posts()->create([
            'body'       => $request->body,
            'username' => Auth::user()->name,
            'photo' => $filename,


        ]); 
        $posts = Post::orderBy('created_at', 'desc')->get();
        return view('home', ['post' => $posts]);
    }

Can anyone please tell me what i am missing



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2kieVo6
via IFTTT

Aucun commentaire:

Enregistrer un commentaire