小编Mut*_*iti的帖子

如何使用计算值,就像它是Laravel模型中的列值一样?

我有一个项目模型,看起来像这样:

class Product extends Model
{
    public $timestamps = true;
    protected $guarded = ['id'];
    protected $table = 'products';
    protected $hidden = ['created_at', 'updated_at'];
    protected $fillable = ['name', 'category_id', 'units', 'b_price', 's_price', 'warn_count', 'added_by'];

    public function category()
    {
        return $this->belongsTo('App\Category');
    }

    public function stock(){
        $product_id = $this->id;
        $filter = ['product_id' => $product_id];
        //STOCK PLUS
        //credit purchases
        $cr_purchases = CreditPurchase::where($filter)->sum('qty');
        //purchases
        $purchases = Purchase::where($filter)->sum('qty');
        //returns in
        $re_in = ReturnIn::where($filter)->sum('qty');
        //STOCK MINUS
        //credit sales
        $cr_sales = CreditSale::where($filter)->sum('qty');
        //sales
        $sales = Sale::where($filter)->sum('qty');
        //returns out …
Run Code Online (Sandbox Code Playgroud)

php laravel

5
推荐指数
1
解决办法
2053
查看次数

打印wchar_t会产生奇怪的输出

运行此代码段:

wchar_t *wstr = L"áßå®";
wprintf(L"%s",wstr);
Run Code Online (Sandbox Code Playgroud)

给出输出:

«

代替

áßå®

我是新来的wchar_t.我如何获得预期的输出?

c printf wchar-t format-specifiers

3
推荐指数
1
解决办法
437
查看次数

如何在C++中捕获char*异常

我试图在main()中捕获char*类型异常,但程序崩溃时出现以下消息:在抛出'char const*'实例后调用terminate这是代码:

#include <iostream>

int main ()
{
    char myarray[10];
    try
    {
        for (int n=0; n<=10; n++)
        {
            if (n>9)
            throw "Out of range";
            myarray[n]='a';
        }
    }
    catch (char * str)
    {
        std::cout << "Exception: " << str << std::endl;
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ exception

3
推荐指数
1
解决办法
5240
查看次数

标签 统计

c ×1

c++ ×1

exception ×1

format-specifiers ×1

laravel ×1

php ×1

printf ×1

wchar-t ×1