app/Http/Controllers/ThreadController.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(Spam $spam, Recaptcha $recaptcha)
    {
        request()->validate([
            'title' => ['required', new SpamFree()],
            'body' => ['required', new SpamFree()],
            'channel_id' => [
                'required',
                Rule::exists('channels', 'id')->where(function ($query) {
                    $query->where('archived', false);
                })
            ],
            'g-recaptcha-response' => ['required', $recaptcha]
        ]);
        $thread = Thread::create([
            'user_id' => auth()->id(),
            'channel_id' => request('channel_id'),
            'title' => request('title'),
            'body' => request('body'),
        ]);
        if (request()->wantsJson()) {
            return response($thread, 201);
        }
        return redirect($thread->path())
            ->with('flash', 'Your thread has been published!');
    }
public function store ( Spam $ spam , Recaptcha $ recaptcha ) { request ( ) -> validate ( [ 'title' => [ 'required' , new SpamFree ( ) ] , 'body' => [ 'required' , new SpamFree ( ) ] , 'channel_id' => [ 'required' , Rule :: exists ( 'channels' , 'id' ) -> where ( function ( $ query ) { $ query -> where ( 'archived' , false ) ; } ) ] , 'g-recaptcha-response' => [ 'required' , $ recaptcha ] ] ) ; $ thread = Thread :: create ( [ 'user_id' => auth ( ) -> id ( ) , 'channel_id' => request ( 'channel_id' ) , 'title' => request ( 'title' ) , 'body' => request ( 'body' ) , ] ) ; if ( request ( ) -> wantsJson ( ) ) { return response ( $ thread , 201 ) ; } return redirect ( $ thread -> path ( ) ) -> with ( 'flash' , 'Your thread has been published!' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
/* if(! auth()->user()->confirmed) {
            return redirect('/threads')->with('flash','You must first confirm your email address.');
        } */ // 'channel_id' => 'required|exists:channels,id', // $spam->detect(request('body')); // No longer need to, happened automatically by the model event /* 'slug' => str_slug(request('title')) */ // return redirect(route('threads.show', ['channel' => $thread->channel->slug, 'thread' => $thread->id]))