0

那是控制器

public function hitung($request, $response, $args)

{  

    $datauser = User::with(['usia','aktivitas'])->find($args['id']);


    $tinggi         = $datauser['tinggi'];
    $berat          = $datauser['berat'];
    $nama           = $datauser['nama'];
    $umur           = $datauser['umur'];
    $aktivitas      = $datauser['aktivitaas_id'];
    $usia           = $datauser['usia_id'];
    $nilai          = $datauser->aktivitas->nilai;
    $energy         = $datauser->usia->energy;
    $protein        = $datauser->usia->protein;
    $lemak          = $datauser->usia->lemak;
    $karbohidrat    = $datauser->usia->karbohidrat;

    $amb = 655 + (9.6 * $berat) + (1.8 * $tinggi) - (4.7 * $umur);
    $amb = round($amb);

    $energytotal = $amb * $nilai + $energy;
    $energytotal = round($energytotal);
    $protein     = (15 * $energytotal / 100) + $protein;
    $protein = round($protein);
    $lemak       = (25 * $energytotal / 100) + $lemak;
    $lemak = round($lemak);
    $karbohidrat = ($energytotal - ($protein + $lemak)) + $karbohidrat;
    $karbohidrat= round($karbohidrat);

    return $response ->withJson([
            'Nama'  => $nama,
            'total_energy' => $energytotal , 
            'Protein'=> $protein,
            'lemak'=> $lemak,
            'Karbohidrat'=> $karbohidrat,
            ]);


}

这就是用户模型:

    <?php

namespace App\models;

use Illuminate\Database\Eloquent\Model;

class User extends Model



{
    public   $timestamps  = false;

protected $fillable = ['username', 'password', 'nama', 'tinggi', 'berat', 'umur', 'usia_id', 'aktivitas_id'];

protected $table    = "users";

 public function usia()
{
    return $this->belongsTo('App\Models\Usia');
}

public function aktivitas()
{
    return $this->belongsTo('App\Models\Aktivitas');
}

    public function forum()
{
    return $this->hasMany('App\Models\Forum');
    }

}

这就是 aktivitas 模型:

        <?php

    namespace App\models;

    use Illuminate\Database\Eloquent\Model;

    class Aktivitas extends Model 

{

    protected $table    = "aktivitas";
public function user()
{
    return $this->hasMany('App\Models\User');
}

}

这就是usia模式,

  <?php

namespace App\models;

use Illuminate\Database\Eloquent\Model;

class Usia extends Model 
{
protected $table    = "usia";

public function user()
{
    return $this->hasMany('App\Models\User');
    }

}

此代码在本地工作,但是当我托管它时,它没有工作,请帮助我的考试...

我认为问题出在这段代码中,

$datauser = User::with(['usia','aktivitas'])->find($args['id']);

有什么不同的方法吗?

4

1 回答 1

0

我猜你的本地是 Windows,远程主机是 Linux

首先,您应该知道 windows 文件和文件夹名称不区分大小写,并且 windows 操作系统中的模型和模型之间没有区别

但 Linux 文件和目录名称区分大小写

在您的代码中:

namespace App\models;

return $this->hasMany('App\Models\User');

你使用的地方Modelsmodels

您应该检查目录名称并将其重命名为您写错单词的任何地方

于 2017-07-04T07:06:36.383 回答