Hsmith1947's avatar

Laravel Video, Audio and image upload

This is my image upload method

public function store(Request $request, User $user, Image $image)
    {
        $this->validate($request, [
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
            'body' => 'required'
        ]);


        if( $request->hasFile('image') ) {
            $image = $request->file('image');
            $filename = time() . '.' . $image->getClientOriginalExtension();
            
            Image::make($image)->save( public_path('uploads/images/' . $filename ) );
        } 
        
        $image = $filename;

        auth()->user()->publish(
            new Post(['body' => request('body'), 'image' => $image, 'user_id' => auth()->id()])
        );

        return redirect('/');
    }

I want one method to upload image, video and audio as well with one input How can i do all these things in one controller?

0 likes
4 replies
AhmadGomaa's avatar

You can do that by add rules in mimes

$this->validate($request, [ 'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg,mp3,mpeg,mp4,3gp|max:2048', 'body' => 'required' ]);

AhmadGomaa's avatar

Then where Is the problem ? Can you tell me what you really want to help you .

jlrdw's avatar

There have been many post on this already. I myself have answered about image upload. There is no way you could do a search.

Please or to participate in this conversation.