如何在 Laravel 中划分两列?

用户10378098

我正在检索每页每个 ID 的行,没有问题。我在 DB 的表中有两列是扩展和价格。我想对这些列值使用除法运算。我的检索代码就在下面。我还想将此代码添加为除法数学!extend / price

public function show($id)
{
    $estates = allestates::where('id', $id)->first();

    return view('pages.show', ['estates' => $estates]);
}

谢谢你的协助!

用户10186369

你应该试试这个:

public function show($id)
{
    $estates = allestates::where('id', $id)->first();

    $rsltActualPrice = $estates->extend / $estates->price;

    return view('pages.show', compact('estates','rsltActualPrice'));
}

$rsltActualPrice这个变量在像视图文件:

{{$rsltActualPrice}}

或者

更改您的视图文件代码,如:

{{$estates->extend / $estates->price}}

更新答案

public function show($id)
{
    $estates = allestates::where('id', $id)->first();

print('<pre style="color:red;">');
print_r($estates);
print('</pre>');
exit;

$rsltActualPrice = $estates->extend / $estates->price;

return view('pages.show', compact('estates','rsltActualPrice'));

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章