app/Http/Controllers/PostsController.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)
    {
        $this->validate($request, [
            'title' => 'required',
            'featured' => 'required|image',
            'content' => 'required',
            'category_id' => 'required',
            'tags' => 'required'
        ]);
        $featured = $request->featured;
        $featured_new_name = time().$featured->getClientOriginalName();
        $featured->move('uploads/posts', $featured_new_name);
        $post = Post::create([
            'title' => $request->title,
            'content' => $request->content,
            'featured' => 'uploads/posts/'.$featured_new_name,
            'category_id' => $request->category_id,
            'slug' => str_slug($request->title),
            'user_id' => Auth::id()
        ]);
        $post->tags()->attach($request->tags);
        Session::flash('success', 'Post created successfully');
        return redirect()->route('posts');
    }
public function store ( Request $ request ) { $ this -> validate ( $ request , [ 'title' => 'required' , 'featured' => 'required|image' , 'content' => 'required' , 'category_id' => 'required' , 'tags' => 'required' ] ) ; $ featured = $ request -> featured ; $ featured_new_name = time ( ) . $ featured -> getClientOriginalName ( ) ; $ featured -> move ( 'uploads/posts' , $ featured_new_name ) ; $ post = Post :: create ( [ 'title' => $ request -> title , 'content' => $ request -> content , 'featured' => 'uploads/posts/' . $ featured_new_name , 'category_id' => $ request -> category_id , 'slug' => str_slug ( $ request -> title ) , 'user_id' => Auth :: id ( ) ] ) ; $ post -> tags ( ) -> attach ( $ request -> tags ) ; Session :: flash ( 'success' , 'Post created successfully' ) ; return redirect ( ) -> route ( 'posts' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .