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)
    {
        $request->validate([
            'content' => 'required',
            'title' =>'required',
            'category' => 'required',
            'image' => 'required|image'
        ]);
        $newPost = new Post;
        $newPost->content = $request->content;
        $newPost->title = $request->title;
        $newPost->category_id = $request->category;
        $imgName = $request->file('image')->getClientOriginalName();
        $request->file('image')->store('public/upload/'.'/'.$imgName);
        $newPost->image = 'storage/upload'.'/'.$imgName;
        $newPost->save();
        return redirect()->route('post.index');
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'content' => 'required' , 'title' => 'required' , 'category' => 'required' , 'image' => 'required|image' ] ) ; $ newPost = new Post ; $ newPost -> content = $ request -> content ; $ newPost -> title = $ request -> title ; $ newPost -> category_id = $ request -> category ; $ imgName = $ request -> file ( 'image' ) -> getClientOriginalName ( ) ; $ request -> file ( 'image' ) -> store ( 'public/upload/' . '/' . $ imgName ) ; $ newPost -> image = 'storage/upload' . '/' . $ imgName ; $ newPost -> save ( ) ; return redirect ( ) -> route ( 'post.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//$newPost->create($request->all());