/** * Display a listing of the resource. * * @return Response */ public function index() { if (Auth::user()->isSuperAdmin() || Auth::user()->isAdmin()) { if (Auth::user()->isSuperAdmin()) { $filter = \DataFilter::source(Device::with('Vehicle', 'Company')); } else { if (Auth::user()->isAdmin()) { $filter = \DataFilter::source(Device::with('Vehicle')->where('company_id', Auth::user()->company_id)); } } $filter->add('name', 'Identificação', 'text'); $filter->add('serial', 'Serial', 'text')->clause('where')->operator('='); $filter->add('model', 'Modelo', 'select')->option('', 'Modelo')->options(config("dropdown.devices")); $filter->add('hasvehicle', 'Atribuído', 'select')->options(array(0 => 'Todos', 1 => 'Com veículo', 2 => 'Sem Veículo'))->scope('hasvehicle'); if (Auth::user()->isSuperAdmin()) { $filter->add('company_id', '', 'select')->option('', 'Empresa')->options(Company::lists("name", "id")->all()); } $filter->submit('Buscar'); $filter->reset('Limpar'); $filter->build(); $grid = \DataGrid::source($filter); $grid->label('Aparelhos'); $grid->attributes(array("class" => "table table-striped")); $grid->add('name', 'Identificação', true); $grid->add('serial', 'Número de Série', true); $grid->add('{{ fieldValue("devices", $model) }}', 'Modelo', 'model'); $grid->add('Vehicle.plate', 'Veículo'); if (Auth::user()->isSuperAdmin()) { $grid->add('Company.name', 'Empresa', 'company_id'); $grid->add('<a title="Visualizar" href="devices/edit?show={{$id}}"><span class="glyphicon glyphicon-eye-open"> </span></a> <a title="Modificar" href="devices/edit?modify={{$id}}"><span class="glyphicon glyphicon-edit"> </span></a> <a title="Última Posição" href="devices/test/{{$id}}"><span class="glyphicon glyphicon-thumbs-up"> </span></a> <a title="Enviar Comando" href="commands/send/{{$id}}"><span class="glyphicon glyphicon-share-alt"> </span></a>', 'Ações'); $grid->link('devices/edit', "Novo Aparelho", "TR"); } else { $grid->add('<a title="Visualizar" href="devices/edit?show={{$id}}"><span class="glyphicon glyphicon-eye-open"> </span></a> <a title="Modificar" href="devices/edit?modify={{$id}}"><span class="glyphicon glyphicon-edit"> </span></a> <a title="Instalar/Remover" href="devices/vehicle/{{$id}}"><span class="glyphicon glyphicon-wrench"> </span></a> <a title="Última Posição" href="devices/test/{{$id}}"><span class="glyphicon glyphicon-thumbs-up"> </span></a>', 'Ações'); } $grid->link('devices/test', "Teste por Serial", "TR"); $grid->paginate(10); return view('devices::index', compact('filter', 'grid')); } else { return view('errors.503'); } }