app/Http/Controllers/Admin/BroadcastsController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Broadcast  $broadcast
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, Broadcast $broadcast)
    {
        if (Gate::denies('manage-cms')){
            return redirect()->route('admin.broadcasts.edit', $broadcast);
        }
        $validator = Validator::make($request->all(), [
            'title'             => ['required', 'string'],
            'subject'           => ['required', 'string'],
            'mail_template'     => ['required', 'string'],
            'status'            => ['nullable', 'integer'],
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.broadcasts.edit', $broadcast);
        }
        $data = $request->all();
        $broadcast->title = $data['title'];
        $broadcast->subject = $data['subject'];
        $broadcast->content = $data['mail_template'];
        $broadcast->status = $data['status'];
        if(!$broadcast->save()) {
            $request->session()->flash('error', 'There is an error modifying information!');
            return redirect()->route('admin.broadcasts.edit', $broadcast);
        }
        $request->session()->flash('success', 'You have modified information!');
        return redirect()->route('admin.broadcasts.index');
    }
public function update ( Request $ request , Broadcast $ broadcast ) { if ( Gate :: denies ( 'manage-cms' ) ) { return redirect ( ) -> route ( 'admin.broadcasts.edit' , $ broadcast ) ; } $ validator = Validator :: make ( $ request -> all ( ) , [ 'title' => [ 'required' , 'string' ] , 'subject' => [ 'required' , 'string' ] , 'mail_template' => [ 'required' , 'string' ] , 'status' => [ 'nullable' , 'integer' ] , ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.broadcasts.edit' , $ broadcast ) ; } $ data = $ request -> all ( ) ; $ broadcast -> title = $ data [ 'title' ] ; $ broadcast -> subject = $ data [ 'subject' ] ; $ broadcast -> content = $ data [ 'mail_template' ] ; $ broadcast -> status = $ data [ 'status' ] ; if ( ! $ broadcast -> save ( ) ) { $ request -> session ( ) -> flash ( 'error' , 'There is an error modifying information!' ) ; return redirect ( ) -> route ( 'admin.broadcasts.edit' , $ broadcast ) ; } $ request -> session ( ) -> flash ( 'success' , 'You have modified information!' ) ; return redirect ( ) -> route ( 'admin.broadcasts.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .