geetpurwar
1 year ago

Model Update Error

Posted 1 year ago by geetpurwar

Hi, I have created a website Model, which has certain fields. Only 'name' field is required.

However, if I submit without entering any other field, I always get following errors. What am I doing wrong?

{"welcome_push_link":["The welcome push link must be at least 2 characters.","The welcome push link format is invalid."]}

I am using following update method in Website Controller.

public function update(User $user, Request $request, Website $website)
    {
        if(auth()->user()->id == $website->user_id):

            $this->validate($request, [
                'name'                       => 'required|min:2',
                'icon'                       => 'image|mimes:jpeg,png,jpg,gif,svg|max:10048',
                'timezone'                   => 'required',
                'opt_in_type'                => 'min:2',
                'opt_in_theme'               => 'min:2',
                'chicklet_position'          => 'min:2',
                'chicklet_default_text'      => 'min:2',
                'chicklet_enable_text'       => 'min:2',
                'chicklet_disable_text'      => 'min:2',
                'chicklet_wait_text'         => 'min:2',
                'chicklet_incompatible_text' => 'min:2',
                'optin_title'                => 'min:2',
                'optin_subtitle'             => 'min:2',
                'optin_allow'                => 'min:2',
                'optin_close'                => 'min:2',
                'welcome_push_title'         => 'min:2',
                'welcome_push_body'          => 'min:2',
                'welcome_push_link'          => 'min:10'
            ]);

            $filename = NULL;
            if( $request->hasFile('icon') ) {
                $website->icon_s3 = uploadAndReturnLink($request->file('icon'), 'websiteIcons', 's3');
                $website->icon_local = uploadAndReturnLink($request->file('icon'), 'websiteIcons', 'local');
            }

            $website->name                       = $request->name;
            $website->timezone                   = $request->timezone;
            $website->opt_in_type                = $request->opt_in_type;
            $website->opt_in_theme               = $request->opt_in_theme;
            $website->chicklet_position          = $request->chicklet_position;
            $website->chicklet_default_text      = $request->chicklet_default_text;
            $website->chicklet_enable_text       = $request->chicklet_enable_text;
            $website->chicklet_disable_text      = $request->chicklet_disable_text;
            $website->chicklet_wait_text         = $request->chicklet_wait_text;
            $website->chicklet_incompatible_text = $request->chicklet_incompatible_text;
            $website->optin_title                = $request->optin_title;
            $website->optin_subtitle             = $request->optin_subtitle;
            $website->optin_allow                = $request->optin_allow;
            $website->optin_close                = $request->optin_close;
            $website->welcome_push_title         = $request->welcome_push_title;
            $website->welcome_push_body          = $request->welcome_push_body;
            $website->welcome_push_link          = $request->welcome_push_link;

            $website->save();

            generateJSFile($website);
            return back()->with('success', 'Settings Updated.');
        endif;
    }

Please sign in or create an account to participate in this conversation.