app/Http/Controllers/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)
    {
        $post = new Post;
        $this->validate($request,[
            'title'     =>  'required|max:100|min:3',
            'category'  =>  'required',
            'content'   =>  'required|max:300',
            'picture'   =>  'required|mimes:jpeg,jpg,png|max:1024'
        ]);
        $post->title = $request['title'];
        $post->content = $request['content'];
        $post->category_id = $request['category'];
        $image = $request->file('picture');
        if ($image) {
            $image_name = $image->getClientOriginalName();
            $image->move(public_path('img'), $image_name);
        } else {
            $image_name = 'no_image.png';
        }
        $post->image = $image_name;
        $post->save();
        Session::flash('success', 'The post has been successfully added');
        return redirect()->route('posts.index');
    }
public function store ( Request $ request ) { $ post = new Post ; $ this -> validate ( $ request , [ 'title' => 'required|max:100|min:3' , 'category' => 'required' , 'content' => 'required|max:300' , 'picture' => 'required|mimes:jpeg,jpg,png|max:1024' ] ) ; $ post -> title = $ request [ 'title' ] ; $ post -> content = $ request [ 'content' ] ; $ post -> category_id = $ request [ 'category' ] ; $ image = $ request -> file ( 'picture' ) ; if ( $ image ) { $ image_name = $ image -> getClientOriginalName ( ) ; $ image -> move ( public_path ( 'img' ) , $ image_name ) ; } else { $ image_name = 'no_image.png' ; } $ post -> image = $ image_name ; $ post -> save ( ) ; Session :: flash ( 'success' , 'The post has been successfully added' ) ; return redirect ( ) -> route ( 'posts.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .