app/Http/Controllers/Admin/PostController.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(Request $request)
    {
        $success = false;
       $this->validate($request,[
        'category_id' => 'required',
        'title' => 'required|unique:posts|min:5',
        'content' => 'required|min:10',
        'status' => 'required',
    ]);
        $get_thumb = $request->thumbnail;
        $thumb_file = explode(';',$request->thumbnail);
        $thumb_file = explode('/',$thumb_file[0]);
        $thumb_file_ext = end($thumb_file);
        $slug = slugify($request->title);
        $file_name =  $slug.'.'.$thumb_file_ext;
        $success = Post::create([
            'user_id' => Auth()->user()->id,
            'category_id' => $request->category_id,
            'title' => $request->title,
            'content' => $request->content,
            'thumbnail' => $file_name,
            'slug' => $slug,
            'status' => $request->status,
        ]);
        return response()->json(['success' => $success],200);
    }
public function store ( Request $ request ) { $ success = false ; $ this -> validate ( $ request , [ 'category_id' => 'required' , 'title' => 'required|unique:posts|min:5' , 'content' => 'required|min:10' , 'status' => 'required' , ] ) ; $ get_thumb = $ request -> thumbnail ; $ thumb_file = explode ( ';' , $ request -> thumbnail ) ; $ thumb_file = explode ( '/' , $ thumb_file [ 0 ] ) ; $ thumb_file_ext = end ( $ thumb_file ) ; $ slug = slugify ( $ request -> title ) ; $ file_name = $ slug . '.' . $ thumb_file_ext ; $ success = Post :: create ( [ 'user_id' => Auth ( ) -> user ( ) -> id , 'category_id' => $ request -> category_id , 'title' => $ request -> title , 'content' => $ request -> content , 'thumbnail' => $ file_name , 'slug' => $ slug , 'status' => $ request -> status , ] ) ; return response ( ) -> json ( [ 'success' => $ success ] , 200 ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//Check Validation // Get the extension of thumbanil //Insert database // if ($success) { //     //Image::make($post_image1)->resize(300,300)->save('public/media/post/'.$post_image_name); //      Image::make($get_thumb)->resize(400,200)->save('public/uploads/posts/'.$file_name); // }