kgp43
9 months ago

How to access functions within a model, in a view

Posted 9 months ago by kgp43

Hi,

How can I access a function within a model? (in a view) I got this small function in my model, and I would like to access it in my view.

namespace App;

use Illuminate\Database\Eloquent\Model;

class Convert extends Model
{
    protected $fillable = [
        'unit_type',
        'unit_num',
    ];
    
    public function pressure() {
        
        # Set base values
        # Base: 1 bar
        $base['bar'] = 1;
        $base['pa'] = 100000;
        $base['mpa'] = 0.1;
        $base['nmm2'] = 0.1;
        $base['psi'] = 14.5038;
        $base['ksi'] = 0.0145037738007;
        
        return $base;
        
    }
}

Added this to my view, but it does not work:

{{ App\Convert::pressure() }}

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