app/Http/Controllers/Admin/BroadcastsController.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)
    {
        if (Gate::denies('manage-cms')){
            return redirect()->route('admin.broadcasts.create');
        }
        $validator = Validator::make($request->all(), [
            'title'             => ['required', 'string', 'min:3', 'max:64'],
            'subject'           => ['required', 'string', 'min:3', 'max:64'],
            'mail_template'     => ['required', 'string'],
            'status'            => ['nullable', 'integer'],
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.broadcasts.create');
        }
        $data = $request->all();
        $broadcast = Broadcast::create([
            'title'             => $data['title'],
            'subject'           => $data['subject'],
            'content'           => $data['mail_template'],
            'status'            => $data['status'],
        ]);
        if($broadcast == NULL) {
            $request->session()->flash('error', 'There is an error creating information!');
            return redirect()->route('admin.broadcasts.create');
        }
        $request->session()->flash('success', 'You have created information!');
        return redirect()->route('admin.broadcasts.index');
    }
public function store ( Request $ request ) { if ( Gate :: denies ( 'manage-cms' ) ) { return redirect ( ) -> route ( 'admin.broadcasts.create' ) ; } $ validator = Validator :: make ( $ request -> all ( ) , [ 'title' => [ 'required' , 'string' , 'min:3' , 'max:64' ] , 'subject' => [ 'required' , 'string' , 'min:3' , 'max:64' ] , 'mail_template' => [ 'required' , 'string' ] , 'status' => [ 'nullable' , 'integer' ] , ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.broadcasts.create' ) ; } $ data = $ request -> all ( ) ; $ broadcast = Broadcast :: create ( [ 'title' => $ data [ 'title' ] , 'subject' => $ data [ 'subject' ] , 'content' => $ data [ 'mail_template' ] , 'status' => $ data [ 'status' ] , ] ) ; if ( $ broadcast == NULL ) { $ request -> session ( ) -> flash ( 'error' , 'There is an error creating information!' ) ; return redirect ( ) -> route ( 'admin.broadcasts.create' ) ; } $ request -> session ( ) -> flash ( 'success' , 'You have created information!' ) ; return redirect ( ) -> route ( 'admin.broadcasts.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .