Reputation: 111
I want to show total count of the unit so I wrote {{ ($unit->unit_id)->count() }}
to return the data.
blade.php
<tbody>
@foreach($developer as $key => $data)
<tr>
<td></td>
<td>{{$data->developer_name}}</td>
<td>
@foreach($data->projects as $key => $project)
<a href="">{{ $project->project_name }}</a><br>
@endforeach
</td>
<td>
@foreach($data->projects as $key => $project)
@foreach($project->phase as $key => $phase)
@foreach($phase->unit as $key => $unit)
<a href="">{{ ($unit->unit_id)->count() }}</a><br> //error
@endforeach
@endforeach
@endforeach
</td>
</tr>
@endforeach
</tbody>
UPDATE:
Unit.php Model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Unit extends Model
{
//
protected $table="pams_unit";
protected $primaryKey="unit_id";
}
UnitController
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Unit;
use App\Developer;
class UnitByDeveloperController extends Controller
{
//
public function __construct()
{
$this->middleware('auth');
}
public function show(Request $request){
$dev_id = $request->input('dev_id');
$developer =Developer::where(function($query1) use($dev_id){
if($dev_id){
$query1
->where('id',$dev_id);
}
})
->active()
->paginate('8');
return view('reportlayout.unitByDeveloper',compact('developer'));
}
}
But, an error is showing :-
Call to a member function count() on integer
Anyone can help me to spot my mistake ?
Upvotes: 0
Views: 1624
Reputation: 2416
Change this:
{{ ($unit->unit_id)->count() }}
To:
{{ $unit->count() }}
Upvotes: 1