towhid
856
12
Laravel

BadMethodCallException Method Illuminate\Http\UploadedFile::getClientOrginalName does not exist.

Posted 8 months ago by towhid

this is my #controller

public function store(Request $request)
    {
        $this->validate($request, [
            'title' => 'required',
            'body' => 'required',
            'cover_image' => 'image|nullable|max:1999',
        ]);

        // Handle File upload
        if($request->hasFile('cover_image')){
            // get filename with the extention
            $fileNameWithExt = $request->file('cover_image')->getClientOrginalName();

            // get just filename 
            $fileName = pathinfo($fileNameWithExt, PATHINFO_FILENAME);

            // get just Ext
            $extention = $request->file('cover_image')->getClientOrginalExtention();

            // Filename to store
            $fileNameToStore = $filename.'_'.time().'.'.$extention;

            // upload image
            $path = $request->file('cover_image')->storeAs('public/cover_images',$fileNameToStore);
        }else{
            $fileNameStore='noimage.jpg';
        }        
        //create post
        $post=new Post;
        $post->title = $request->input('title');
        $post->body = $request->input('body');
        $post->user_id = auth()->user()->id;
        $post->cover_image = $fileNameToStore;
        $post->save();

        return redirect('/posts')->with('success','Post created');

    }

why this error occurd ?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.