I am new in Laravel and I used Laravel 5 for my project. My specification is count the number of before held training according to category of training so i used join and group by and count function to get the number before held training:
In my controller code is as below:-
<?php
namespace App\Http\Controllers;
use Request;
use App\Training;
use App\Schedule;
use App\User;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Requests\TrainingRequest;
use Carbon\Carbon;
class TrainingController extends Controller
{
/**
* Display a listing of the resource.
*
* @return Response
*/
public function __construct(){
$this->middleware('auth',['only'=>'index']);
}
public function index()
{
//
$training=Training::all();
$before_held=Schedule::join('training','training.id','=','schedule.training_id')
->groupBy('training.category')->where('schedule.training_end_date','>=',carbon::now())->get();
// echo count($before_held);
//die();
return view('Training.index',compact('training','before_held'));
}
In View:-
<td><a href="/training/before_held">{{count($before_held)}}</a></td>
This always show 0 count in the table like this:-
|category|Held Before|
|test | 0 |
|test | 0 |
But I need count two if training_end_date greater than or equal to current time.
SO I am thankful if anyone can solve this issue.
Aucun commentaire:
Enregistrer un commentaire