src/Http/Controllers/MessageResourceController.php
public function store(MessageRequest $request)
    {
        try {

            $mail_to = $request->get('mails');
            $status  = $request->get('status');
            $sent    = $request->all();
            $inbox   = $request->all();
            $draft   = $request->all();

            if (empty($mail_to)) {
                return response()->json([
                    'message'  => trans('messages.success.updated', ['Module' => trans('message::message.name')]),
                    'code'     => 204,
                    'redirect' => trans_url('/admin/message/message/0'),
                ], 201);
            }

            foreach ($mail_to as $user_id) {

                if ($status == 'Draft') {
                    //draft
                    $draft['user_id']   = user_id('admin.web');
                    $draft['user_type'] = user_type('admin.web');
                    $draft['to']        = $user_id;
                    $draft['status']    = "Draft";
                    $message1           = $this->repository->create($draft);
                } else {
                    //sent
                    $sent['user_id']   = user_id('admin.web');
                    $sent['user_type'] = user_type('admin.web');
                    $sent['to']        = $user_id;
                    $message           = $this->repository->create($sent);

                    //inbox
                    $inbox['user_id']   = user_id('admin.web');
                    $inbox['user_type'] = user_type('admin.web');
                    $inbox['to']        = $user_id;
                    $inbox['status']    = "Inbox";
                    $message1           = $this->repository->create($inbox);
                }

            }

            $inbox_count = $this->repository->msgCount('Inbox');
            $draft_count = $this->repository->msgCount('Draft');
            $sent_count  = $this->repository->msgCount('Sent');

            return response()->json([
                'message'     => trans('messages.success.updated', ['Module' => trans('message::message.name')]),
                'code'        => 204,
                'redirect'    => trans_url('/admin/message/message/status/Inbox'),
                'inbox_count' => $inbox_count,
                'draft_count' => $draft_count,
                'sent_count'  => $sent_count,
            ], 201);

        } catch (Exception $e) {
            return response()->json([
                'message' => $e->getMessage(),
                'code'    => 400,
            ], 400);
        }

    }
public function store(MessageRequest $request)
    {
        try {

            $mail_to = $request->get('mails');
            $status  = $request->get('status');
            $sent    = $request->all();
            $inbox   = $request->all();
            $draft   = $request->all();

            if (empty($mail_to)) {
                return response()->json([
                    'message'  => trans('messages.success.updated', ['Module' => trans('message::message.name')]),
                    'code'     => 204,
                    'redirect' => trans_url('/admin/message/message/0'),
                ], 201);
            }

            foreach ($mail_to as $user_id) {

                if ($status == 'Draft') {
                    //draft
                    $draft['user_id']   = user_id('admin.web');
                    $draft['user_type'] = user_type('admin.web');
                    $draft['to']        = $user_id;
                    $draft['status']    = "Draft";
                    $message1           = $this->repository->create($draft);
                } else {
                    //sent
                    $sent['user_id']   = user_id('admin.web');
                    $sent['user_type'] = user_type('admin.web');
                    $sent['to']        = $user_id;
                    $message           = $this->repository->create($sent);

                    //inbox
                    $inbox['user_id']   = user_id('admin.web');
                    $inbox['user_type'] = user_type('admin.web');
                    $inbox['to']        = $user_id;
                    $inbox['status']    = "Inbox";
                    $message1           = $this->repository->create($inbox);
                }

            }

            $inbox_count = $this->repository->msgCount('Inbox');
            $draft_count = $this->repository->msgCount('Draft');
            $sent_count  = $this->repository->msgCount('Sent');

            return response()->json([
                'message'     => trans('messages.success.updated', ['Module' => trans('message::message.name')]),
                'code'        => 204,
                'redirect'    => trans_url('/admin/message/message/status/Inbox'),
                'inbox_count' => $inbox_count,
                'draft_count' => $draft_count,
                'sent_count'  => $sent_count,
            ], 201);

        } catch (Exception $e) {
            return response()->json([
                'message' => $e->getMessage(),
                'code'    => 400,
            ], 400);
        }

    }
public function store ( MessageRequest $ request ) { try { $ mail_to = $ request -> get ( 'mails' ) ; $ status = $ request -> get ( 'status' ) ; $ sent = $ request -> all ( ) ; $ inbox = $ request -> all ( ) ; $ draft = $ request -> all ( ) ; if ( empty ( $ mail_to ) ) { return response ( ) -> json ( [ 'message' => trans ( 'messages.success.updated' , [ 'Module' => trans ( 'message::message.name' ) ] ) , 'code' => 204 , 'redirect' => trans_url ( '/admin/message/message/0' ) , ] , 201 ) ; } foreach ( $ mail_to as $ user_id ) { if ( $ status == 'Draft' ) { //draft $ draft [ 'user_id' ] = user_id ( 'admin.web' ) ; $ draft [ 'user_type' ] = user_type ( 'admin.web' ) ; $ draft [ 'to' ] = $ user_id ; $ draft [ 'status' ] = "Draft" ; $ message1 = $ this -> repository -> create ( $ draft ) ; } else { //sent $ sent [ 'user_id' ] = user_id ( 'admin.web' ) ; $ sent [ 'user_type' ] = user_type ( 'admin.web' ) ; $ sent [ 'to' ] = $ user_id ; $ message = $ this -> repository -> create ( $ sent ) ; //inbox $ inbox [ 'user_id' ] = user_id ( 'admin.web' ) ; $ inbox [ 'user_type' ] = user_type ( 'admin.web' ) ; $ inbox [ 'to' ] = $ user_id ; $ inbox [ 'status' ] = "Inbox" ; $ message1 = $ this -> repository -> create ( $ inbox ) ; } } $ inbox_count = $ this -> repository -> msgCount ( 'Inbox' ) ; $ draft_count = $ this -> repository -> msgCount ( 'Draft' ) ; $ sent_count = $ this -> repository -> msgCount ( 'Sent' ) ; return response ( ) -> json ( [ 'message' => trans ( 'messages.success.updated' , [ 'Module' => trans ( 'message::message.name' ) ] ) , 'code' => 204 , 'redirect' => trans_url ( '/admin/message/message/status/Inbox' ) , 'inbox_count' => $ inbox_count , 'draft_count' => $ draft_count , 'sent_count' => $ sent_count , ] , 201 ) ; } catch ( Exception $ e ) { return response ( ) -> json ( [ 'message' => $ e -> getMessage ( ) , 'code' => 400 , ] , 400 ) ; } }
Create new message.

@param Request $request

@return Response
Create new message .