MdAzizurRahman
2 months ago

Image uploaded and Resize

Posted 2 months ago by MdAzizurRahman

public function store(Request $request) { $this->validate($request,[ 'title' =>'required', 'image' => 'mimes:jpeg,jpg,bmp,png'

    ]);


     

      $image = $request->file('image');
    $slug = str_slug($request->title);
    if (isset($image))
    {
        $currentDate = Carbon::now()->toDateString();
        $imagename = $slug.'-'.$currentDate.'-'. uniqid() .'.'. $image->getClientOriginalExtension();
        $image_resize = Image::make($image->getRealPath());   
        $image_resize->resize(1600,1066);
        if (!file_exists('storage/uploads/post'))
        {
            mkdir('storage/uploads/post',0777,true);
        }
        $image_resize->save('storage/uploads/post/'.$imagename);
    }else{
        $imagename = "default.png";
    }

    $post = new Post();
    $post->title = $request->title;
    $post->slug = str_slug($request->title);
    $post->image = $imagename;
    $post->save();
    Toastr::success('Post Successfully Save:)','Success');
    return redirect()->route('admin.post.index');

}

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