app/Http/Controllers/Admin/BlogController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(BlogRequest $request)
    {
        $blog = new Blog();
        if($request->hasFile('blog_image')) {
            $image       = $request->file('blog_image');
            $filename    = $image->getClientOriginalName();
            $image_resize = Image::make($image->getRealPath());              
            $image_resize->resize(500, 500, function ($constraint) {
                $constraint->aspectRatio();
            })->save(public_path('storage/blog/' .$filename));
            $blog->blog_image = $filename;
        }
        $blog->blog_title = $request->blog_title;
        $blog->blog_slug = Str::slug($request->blog_title, '-');
        $blog->blog_short_description = $request->blog_short_description;
        $blog->blog_description = $request->blog_description;
        $blog->blog_seo_title = $request->blog_seo_title;
        $blog->blog_seo_description = $request->blog_seo_description;
        $blog->blog_seo_keyword = $request->blog_seo_keyword;
        $blog->save();
        $blog->blog_category()->sync($request->category_id);
        $blog->blog_tags()->sync($request->tags_id);
        return redirect(route('admin.blog.index'))->with('success','Blog successfully added.');
    }
public function store ( BlogRequest $ request ) { $ blog = new Blog ( ) ; if ( $ request -> hasFile ( 'blog_image' ) ) { $ image = $ request -> file ( 'blog_image' ) ; $ filename = $ image -> getClientOriginalName ( ) ; $ image_resize = Image :: make ( $ image -> getRealPath ( ) ) ; $ image_resize -> resize ( 500 , 500 , function ( $ constraint ) { $ constraint -> aspectRatio ( ) ; } ) -> save ( public_path ( 'storage/blog/' . $ filename ) ) ; $ blog -> blog_image = $ filename ; } $ blog -> blog_title = $ request -> blog_title ; $ blog -> blog_slug = Str :: slug ( $ request -> blog_title , '-' ) ; $ blog -> blog_short_description = $ request -> blog_short_description ; $ blog -> blog_description = $ request -> blog_description ; $ blog -> blog_seo_title = $ request -> blog_seo_title ; $ blog -> blog_seo_description = $ request -> blog_seo_description ; $ blog -> blog_seo_keyword = $ request -> blog_seo_keyword ; $ blog -> save ( ) ; $ blog -> blog_category ( ) -> sync ( $ request -> category_id ) ; $ blog -> blog_tags ( ) -> sync ( $ request -> tags_id ) ; return redirect ( route ( 'admin.blog.index' ) ) -> with ( 'success' , 'Blog successfully added.' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// $img_name = $request->blog_image->getClientOriginalName(); // $image = $request->blog_image->storeAs('blog', $img_name);