php - How to get returned text from model to a controller on Laravel 5.3 -


how grab / returned text model function controller ?? i'm using laravel 5.3 framework example :

//my model class mymodel extends model{    function myfunction(){        if($a == $b){           $text = "a = b";           return $text;        }        else if($a != $b){           $text = "a ! b";           return $text;        }        else{           $text = "some text";           return $text;        }    } } 

and in controller :

//my controller class mycontroller extends controller{    public function test(){      $obj = new mymodel;      $data = $obj->myfunction();      var_dump($data); // want returned myfunction()    } } 

please me :d

thanks attention :)

your code working fine me.you have assign value $a , $b in model

 public function myfunction($a,$b){         if($a == $b){           return "a = b";        }        else if($a != $b){           return "a ! b";        }        else{           return "some text";        }    } 

controller

$obj = new mymodel;      $data = $obj->myfunction(1,2);      var_dump($data); 

result

string(5) "a ! b"  

you can use static method in model

public static function myfunction($a,$b){         if($a == $b){           return "a = b";        }        else if($a != $b){           return "a ! b";        }        else{           return "some text";        }    } 

in controller

$data = user::myfunction(1,2); var_dump($data); 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -