public function store(Request $request)
    {
        $request->request->add(['body_content' => strip_tags($request->body)]);

        $validator = Validator::make($request->all(), [
            'title'               => 'required|min:5|max:255',
            'body_content'        => 'required|min:10',
            'chatter_category_id' => 'required',
         ],[
			'title.required' =>  trans('chatter::alert.danger.reason.title_required'),
			'title.min'     => [
				'string'  => trans('chatter::alert.danger.reason.title_min'),
			],
			'title.max' => [
				'string'  => trans('chatter::alert.danger.reason.title_max'),
			],
			'body_content.required' => trans('chatter::alert.danger.reason.content_required'),
			'body_content.min' => trans('chatter::alert.danger.reason.content_min'),
			'chatter_category_id.required' => trans('chatter::alert.danger.reason.category_required'),
		]);
        

        Event::fire(new ChatterBeforeNewDiscussion($request, $validator));
        if (function_exists('chatter_before_new_discussion')) {
            chatter_before_new_discussion($request, $validator);
        }

        if ($validator->fails()) {
            return back()->withErrors($validator)->withInput();
        }

        $user_id = Auth::user()->id;

        if (config('chatter.security.limit_time_between_posts')) {
            if ($this->notEnoughTimeBetweenDiscussion()) {
                $minutes = trans_choice('chatter::messages.words.minutes', config('chatter.security.time_between_posts'));
                $chatter_alert = [
                    'chatter_alert_type' => 'danger',
                    'chatter_alert'      => trans('chatter::alert.danger.reason.prevent_spam', [
                                                'minutes' => $minutes,
                                            ]),
                    ];

                return redirect('/'.config('chatter.routes.home'))->with($chatter_alert)->withInput();
            }
        }

        // *** Let's gaurantee that we always have a generic slug *** //
        $slug = str_slug($request->title, '-');

        $discussion_exists = Models::discussion()->where('slug', '=', $slug)->withTrashed()->first();
        $incrementer = 1;
        $new_slug = $slug;
        while (isset($discussion_exists->id)) {
            $new_slug = $slug.'-'.$incrementer;
            $discussion_exists = Models::discussion()->where('slug', '=', $new_slug)->withTrashed()->first();
            $incrementer += 1;
        }

        if ($slug != $new_slug) {
            $slug = $new_slug;
        }

        $new_discussion = [
            'title'               => $request->title,
            'chatter_category_id' => $request->chatter_category_id,
            'user_id'             => $user_id,
            'slug'                => $slug,
            'color'               => $request->color,
            ];

        $category = Models::category()->find($request->chatter_category_id);
        if (!isset($category->slug)) {
            $category = Models::category()->first();
        }

        $discussion = Models::discussion()->create($new_discussion);

        $new_post = [
            'chatter_discussion_id' => $discussion->id,
            'user_id'               => $user_id,
            'body'                  => $request->body,
            ];

        if (config('chatter.editor') == 'simplemde'):
           $new_post['markdown'] = 1;
        endif;

        // add the user to automatically be notified when new posts are submitted
        $discussion->users()->attach($user_id);

        $post = Models::post()->create($new_post);

        if ($post->id) {
            Event::fire(new ChatterAfterNewDiscussion($request, $discussion, $post));
            if (function_exists('chatter_after_new_discussion')) {
                chatter_after_new_discussion($request);
            }

            $chatter_alert = [
                'chatter_alert_type' => 'success',
                'chatter_alert'      => trans('chatter::alert.success.reason.created_discussion'),
                ];

            return redirect('/'.config('chatter.routes.home').'/'.config('chatter.routes.discussion').'/'.$category->slug.'/'.$slug)->with($chatter_alert);
        } else {
            $chatter_alert = [
                'chatter_alert_type' => 'danger',
                'chatter_alert'      => trans('chatter::alert.danger.reason.create_discussion'),
            ];

            return redirect('/'.config('chatter.routes.home').'/'.config('chatter.routes.discussion').'/'.$category->slug.'/'.$slug)->with($chatter_alert);
        }
    }
public function store(Request $request)
    {
        $request->request->add(['body_content' => strip_tags($request->body)]);

        $validator = Validator::make($request->all(), [
            'title'               => 'required|min:5|max:255',
            'body_content'        => 'required|min:10',
            'chatter_category_id' => 'required',
         ],[
			'title.required' =>  trans('chatter::alert.danger.reason.title_required'),
			'title.min'     => [
				'string'  => trans('chatter::alert.danger.reason.title_min'),
			],
			'title.max' => [
				'string'  => trans('chatter::alert.danger.reason.title_max'),
			],
			'body_content.required' => trans('chatter::alert.danger.reason.content_required'),
			'body_content.min' => trans('chatter::alert.danger.reason.content_min'),
			'chatter_category_id.required' => trans('chatter::alert.danger.reason.category_required'),
		]);
        

        Event::fire(new ChatterBeforeNewDiscussion($request, $validator));
        if (function_exists('chatter_before_new_discussion')) {
            chatter_before_new_discussion($request, $validator);
        }

        if ($validator->fails()) {
            return back()->withErrors($validator)->withInput();
        }

        $user_id = Auth::user()->id;

        if (config('chatter.security.limit_time_between_posts')) {
            if ($this->notEnoughTimeBetweenDiscussion()) {
                $minutes = trans_choice('chatter::messages.words.minutes', config('chatter.security.time_between_posts'));
                $chatter_alert = [
                    'chatter_alert_type' => 'danger',
                    'chatter_alert'      => trans('chatter::alert.danger.reason.prevent_spam', [
                                                'minutes' => $minutes,
                                            ]),
                    ];

                return redirect('/'.config('chatter.routes.home'))->with($chatter_alert)->withInput();
            }
        }

        
        $slug = str_slug($request->title, '-');

        $discussion_exists = Models::discussion()->where('slug', '=', $slug)->withTrashed()->first();
        $incrementer = 1;
        $new_slug = $slug;
        while (isset($discussion_exists->id)) {
            $new_slug = $slug.'-'.$incrementer;
            $discussion_exists = Models::discussion()->where('slug', '=', $new_slug)->withTrashed()->first();
            $incrementer += 1;
        }

        if ($slug != $new_slug) {
            $slug = $new_slug;
        }

        $new_discussion = [
            'title'               => $request->title,
            'chatter_category_id' => $request->chatter_category_id,
            'user_id'             => $user_id,
            'slug'                => $slug,
            'color'               => $request->color,
            ];

        $category = Models::category()->find($request->chatter_category_id);
        if (!isset($category->slug)) {
            $category = Models::category()->first();
        }

        $discussion = Models::discussion()->create($new_discussion);

        $new_post = [
            'chatter_discussion_id' => $discussion->id,
            'user_id'               => $user_id,
            'body'                  => $request->body,
            ];

        if (config('chatter.editor') == 'simplemde'):
           $new_post['markdown'] = 1;
        endif;

        
        $discussion->users()->attach($user_id);

        $post = Models::post()->create($new_post);

        if ($post->id) {
            Event::fire(new ChatterAfterNewDiscussion($request, $discussion, $post));
            if (function_exists('chatter_after_new_discussion')) {
                chatter_after_new_discussion($request);
            }

            $chatter_alert = [
                'chatter_alert_type' => 'success',
                'chatter_alert'      => trans('chatter::alert.success.reason.created_discussion'),
                ];

            return redirect('/'.config('chatter.routes.home').'/'.config('chatter.routes.discussion').'/'.$category->slug.'/'.$slug)->with($chatter_alert);
        } else {
            $chatter_alert = [
                'chatter_alert_type' => 'danger',
                'chatter_alert'      => trans('chatter::alert.danger.reason.create_discussion'),
            ];

            return redirect('/'.config('chatter.routes.home').'/'.config('chatter.routes.discussion').'/'.$category->slug.'/'.$slug)->with($chatter_alert);
        }
    }
public function store ( Request $ request ) { $ request -> request -> add ( [ 'body_content' => strip_tags ( $ request -> body ) ] ) ; $ validator = Validator :: make ( $ request -> all ( ) , [ 'title' => 'required|min:5|max:255' , 'body_content' => 'required|min:10' , 'chatter_category_id' => 'required' , ] , [ 'title.required' => trans ( 'chatter::alert.danger.reason.title_required' ) , 'title.min' => [ 'string' => trans ( 'chatter::alert.danger.reason.title_min' ) , ] , 'title.max' => [ 'string' => trans ( 'chatter::alert.danger.reason.title_max' ) , ] , 'body_content.required' => trans ( 'chatter::alert.danger.reason.content_required' ) , 'body_content.min' => trans ( 'chatter::alert.danger.reason.content_min' ) , 'chatter_category_id.required' => trans ( 'chatter::alert.danger.reason.category_required' ) , ] ) ; Event :: fire ( new ChatterBeforeNewDiscussion ( $ request , $ validator ) ) ; if ( function_exists ( 'chatter_before_new_discussion' ) ) { chatter_before_new_discussion ( $ request , $ validator ) ; } if ( $ validator -> fails ( ) ) { return back ( ) -> withErrors ( $ validator ) -> withInput ( ) ; } $ user_id = Auth :: user ( ) -> id ; if ( config ( 'chatter.security.limit_time_between_posts' ) ) { if ( $ this -> notEnoughTimeBetweenDiscussion ( ) ) { $ minutes = trans_choice ( 'chatter::messages.words.minutes' , config ( 'chatter.security.time_between_posts' ) ) ; $ chatter_alert = [ 'chatter_alert_type' => 'danger' , 'chatter_alert' => trans ( 'chatter::alert.danger.reason.prevent_spam' , [ 'minutes' => $ minutes , ] ) , ] ; return redirect ( '/' . config ( 'chatter.routes.home' ) ) -> with ( $ chatter_alert ) -> withInput ( ) ; } } // *** Let's gaurantee that we always have a generic slug *** // $ slug = str_slug ( $ request -> title , '-' ) ; $ discussion_exists = Models :: discussion ( ) -> where ( 'slug' , '=' , $ slug ) -> withTrashed ( ) -> first ( ) ; $ incrementer = 1 ; $ new_slug = $ slug ; while ( isset ( $ discussion_exists -> id ) ) { $ new_slug = $ slug . '-' . $ incrementer ; $ discussion_exists = Models :: discussion ( ) -> where ( 'slug' , '=' , $ new_slug ) -> withTrashed ( ) -> first ( ) ; $ incrementer += 1 ; } if ( $ slug != $ new_slug ) { $ slug = $ new_slug ; } $ new_discussion = [ 'title' => $ request -> title , 'chatter_category_id' => $ request -> chatter_category_id , 'user_id' => $ user_id , 'slug' => $ slug , 'color' => $ request -> color , ] ; $ category = Models :: category ( ) -> find ( $ request -> chatter_category_id ) ; if ( ! isset ( $ category -> slug ) ) { $ category = Models :: category ( ) -> first ( ) ; } $ discussion = Models :: discussion ( ) -> create ( $ new_discussion ) ; $ new_post = [ 'chatter_discussion_id' => $ discussion -> id , 'user_id' => $ user_id , 'body' => $ request -> body , ] ; if ( config ( 'chatter.editor' ) == 'simplemde' ) : $ new_post [ 'markdown' ] = 1 ; endif ; // add the user to automatically be notified when new posts are submitted $ discussion -> users ( ) -> attach ( $ user_id ) ; $ post = Models :: post ( ) -> create ( $ new_post ) ; if ( $ post -> id ) { Event :: fire ( new ChatterAfterNewDiscussion ( $ request , $ discussion , $ post ) ) ; if ( function_exists ( 'chatter_after_new_discussion' ) ) { chatter_after_new_discussion ( $ request ) ; } $ chatter_alert = [ 'chatter_alert_type' => 'success' , 'chatter_alert' => trans ( 'chatter::alert.success.reason.created_discussion' ) , ] ; return redirect ( '/' . config ( 'chatter.routes.home' ) . '/' . config ( 'chatter.routes.discussion' ) . '/' . $ category -> slug . '/' . $ slug ) -> with ( $ chatter_alert ) ; } else { $ chatter_alert = [ 'chatter_alert_type' => 'danger' , 'chatter_alert' => trans ( 'chatter::alert.danger.reason.create_discussion' ) , ] ; return redirect ( '/' . config ( 'chatter.routes.home' ) . '/' . config ( 'chatter.routes.discussion' ) . '/' . $ category -> slug . '/' . $ slug ) -> with ( $ chatter_alert ) ; } }
Store a newly created resource in storage.

@param \Illuminate\Http\Request $request

@return \Illuminate\Http\Response
Store a newly created resource in storage .