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)
    {
        $this->validate($request,[
            'title' => 'required|max:255',
            'featured' => "required|image",
            'content' => 'required',
            'user_id' => 'required',
            'category_id' => 'required',
            'keyword' => 'max:255',
            'short_desc' => 'max:500',
            'price' => 'integer'
        ]);
        $featured = $request->featured;
        $featured_new_name = time().$featured->getClientOriginalName();
        $featured->move('admin/uploads/images',$featured_new_name);
        $post = Post::create([
            'title' => $request->title,
            'content' => $request ->content,
            'keyword' => $request->keyword,
            'short_desc' => $request->short_desc,
            'featured' => 'admin/uploads/images/'.$featured_new_name,
            'slug' => str_slug($request->title),
            'user_id' => $request->user_id,
            'category_id' => $request ->category_id,
            'tour_date' => $request->tour_date,
            'price' => $request->price,
        ]);
        $post->tags()->attach($request->tags);
        Session::flash('success','You have created Post succesfully');
        return redirect()->back();
    }
public function store ( Request $ request ) { $ this -> validate ( $ request , [ 'title' => 'required|max:255' , 'featured' => " required|image " , 'content' => 'required' , 'user_id' => 'required' , 'category_id' => 'required' , 'keyword' => 'max:255' , 'short_desc' => 'max:500' , 'price' => 'integer' ] ) ; $ featured = $ request -> featured ; $ featured_new_name = time ( ) . $ featured -> getClientOriginalName ( ) ; $ featured -> move ( 'admin/uploads/images' , $ featured_new_name ) ; $ post = Post :: create ( [ 'title' => $ request -> title , 'content' => $ request -> content , 'keyword' => $ request -> keyword , 'short_desc' => $ request -> short_desc , 'featured' => 'admin/uploads/images/' . $ featured_new_name , 'slug' => str_slug ( $ request -> title ) , 'user_id' => $ request -> user_id , 'category_id' => $ request -> category_id , 'tour_date' => $ request -> tour_date , 'price' => $ request -> price , ] ) ; $ post -> tags ( ) -> attach ( $ request -> tags ) ; Session :: flash ( 'success' , 'You have created Post succesfully' ) ; return redirect ( ) -> back ( ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// dd($request->all());