简体   繁体   中英

laravel counting two different table, after getting two values convert in single value

laravel counting two different table, example(table-A,table-B) after counting we get two different values that two values example(table-A=10,table-B=10) how to sum that value example(table-A=10 + table-B=10), total value 20 and pass that in view

public function index() 
{
 $table-A = A::all()->count(); 
$table-B = B::all()->count(); 
return view('home',compact('table-A','table-B')) 
}

Do this that way:

public function index()
{
    $tableA = A::all()->count();
    $tableB = B::all()->count();
    $sum = $tableA + $tableB;
    return view('home',compact('tableA','tableB', 'sum'))
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM