muazzamazaz
1 year ago

Call to a member function getUpdatedTemplate() on null

Posted 1 year ago by muazzamazaz
    public function Save_Template(Request $request)
    {
        $templateValidation = new Notification_Template();
        $validator       = $templateValidation->getValidatedData($request);
        $template           = Notification_Template::find($request->id);

        if ($validator->fails()) {
            $error_messages = implode(',', $validator->messages()->all());
            return back()->with('flash_errors', $error_messages);
        } else {
            $template->getUpdatedTemplate($template, $request);
          
       

            return back()->with('flash_success', Helper::tr('admin_not_profile'));
        }
    }

at above getUpdatedTemplate error throws:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Validator;

/**
 * Responsible for the Admin user
 */
class Notification_Template extends Model
{
    /**
     * Pass the data through the Laravel validator
     * 
     * @param Request $request
     * @return mixed
     */
     public function setUp() {
    parent::setUp();
    // Your code here
}
     protected $table = 'notification_templates';
     protected $guarded = ['Id'];
    protected function passDataThroughValidator(Request $request)
    {
        
           return Validator::make($request->all(), array(
                    'type' => 'max:20',
                    'email_subject' => 'max:300',                    
                    'nessage' => 'max:1000',
                    'title' => 'max:100',                   
                        )
        );
    }
    
    /**
     * Return the updated data after validation
     * 
     * @param Request $request
     * @return mixed
     */

    public function getValidatedData(Request $request)
    {
        return $this->passDataThroughValidator($request);
    }
    
    /**
     * Update the admin profile information
     * 
     * @param \App\Admin $admin
     * @param Request $request
     * @return \App\Admin
     */
    private function updateTemplate(Notification_Template $template, Request $request)
    {
        $template->type = $request->has('type') ? $request->type : $Template->type;
        $template->title = $request->has('title') ? $request->title : $Template->title;
        $Template->email_subject = $request->has('email_subject') ? $request->email_subject : $template->email_subject;
        $Template->message = $request->has('message') ? $request->message : $template->message;
        
        return $template;
    }
  
  private function savetemplateProfile(Notification_Template $template, Request $request)
    {
         $template->type = $request->has('type') ? $request->type : $Template->type;
        $template->title = $request->has('title') ? $request->title : $Template->title;
        $Template->email_subject = $request->has('email_subject') ? $request->email_subject : $template->email_subject;
        $Template->message = $request->has('message') ? $request->message : $template->message;
        
        return $template;
    }
    
    /**
     * Return the updated template profile information
     * 
     * @param \App\template $template
     * @param Request $request
     * @return mixed
     */

     public function getUpdatedtemplate(Notification_Template $template, Request $request)
    {
        return $this->updatetemplate($template, $request);
    }
    
     public function getSavetemplate(Notification_Template $template, Request $request)
    {
        return $this->savetemplate($template, $request);
    }
}

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