Anil Kumar Sahu
Anil Kumar Sahu

Reputation: 577

how can i call laravel model method like modelname->save() inside the laravel view

hi i have a project in laravel 5.4 for some function i have calling the laravel model methods inside the view for my convenient so it is showing me error save() method does not exist so anyone help me is that possible to call the laravel model method inside the view or how to achieve this below is my code

below is my blade code

   $pi_amount=new App\PI_Amount;
                    $pi_amount->invoiceNumber=$fd->invoiceNumber;
                    $pi_amount->total_goods=$total_goods;
                    $pi_amount->total_cst=$total_tax;
                    $pi_amount->total_security=$security_amount;
                    $pi_amount->freight=$freight;
                    $pi_amount->total_value=$total_value;
                    $pi_amount->save();

Upvotes: 1

Views: 405

Answers (2)

Anil Kumar Sahu
Anil Kumar Sahu

Reputation: 577

Hi i have create a new static function inside the Controller and call the that static method inside the view and define the process code inside the controller function so my problem resolve.

Below is my controller function

public static function  processsAmount($insert_data){
                $pi_amount=new PI_Amount;
                $pi_amount->invoiceNumber=$insert_data['invoiceNumber'];
                $pi_amount->total_goods=$insert_data['total_goods'];
                $pi_amount->total_cst=$insert_data['total_cst'];
            $pi_amount->total_security=$insert_data['total_security'];
                $pi_amount->freight=$insert_data['freight'];
                $pi_amount->total_value=$insert_data['total_value'];
                $pi_amount->save();


}

and below i have make a call of that static function inside the view like

    $security_amount=0;
   $insert_data=array('invoiceNumber'=>$fd->invoiceNumber,'total_goods'=>$total_goods,'total_cst'=>$total_tax,'freight'=>$freight,'total_value'=>$total_value,'total_security'=>$security_amount);
  echo App\Http\Controllers\PiController::processsAmount($insert_data);

so by using the above concept my problem is resolved and we can use this for further.

Upvotes: 1

FQuijada
FQuijada

Reputation: 219

Make sure: 1. That is the name of the model PI_Amount 2. That it is the model on App\PI_Amount You can import the model it using at the beginning of the php file:

use App\PI_Amount;

Upvotes: 1

Related Questions