Skip to content

Commit

Permalink
fixed #16
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Sep 21, 2017
1 parent 173f375 commit d4320ab
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
3 changes: 1 addition & 2 deletions app/Filters/Companies/Companies.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class Companies extends ModelFilter

public function search($query)
{
$this->related('settings','settings.key', '=',"'company_name'");
return $this->related('settings','settings.value', 'LIKE',"'%" . $query . "%'");
return $this->whereLike('value', $query);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Companies/Companies.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Companies extends Controller
*/
public function index()
{
$companies = Auth::user()->companies()->get()->sortBy('name');
$companies = Auth::user()->companies()->collect();

foreach ($companies as $company) {
$company->setSettings();
Expand Down
34 changes: 33 additions & 1 deletion app/Models/Company/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Company extends Eloquent
*
* @var array
*/
public $sortable = ['domain'];
public $sortable = ['name', 'domain', 'email'];

public function accounts()
{
Expand Down Expand Up @@ -196,4 +196,36 @@ public function scopeCollect($query, $sort = 'name')

return $this->filter($input)->sortable($sort)->paginate($limit);
}

/**
* Sort by company name
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param $direction
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function nameSortable($query, $direction)
{
return $query->join('settings', 'companies.id', '=', 'settings.company_id')
->where('key', 'general.company_name')
->orderBy('value', $direction)
->select('companies.*');
}

/**
* Sort by company email
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param $direction
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function emailSortable($query, $direction)
{
return $query->join('settings', 'companies.id', '=', 'settings.company_id')
->where('key', 'general.company_email')
->orderBy('value', $direction)
->select('companies.*');
}
}
15 changes: 10 additions & 5 deletions resources/views/companies/companies/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@
<table class="table table-bordered table-striped table-hover" id="tbl-companies">
<thead>
<tr>
<th>@sortablelink('company_name', trans('general.name'))</th>
<th>@sortablelink('domain', trans('companies.domain'))</th>
<th>@sortablelink('company_email', trans('general.email'))</th>

<th style="width: 15%;">{{ trans('general.actions') }}</th>
<th class="col-md-5">@sortablelink('name', trans('general.name'))</th>
<th class="col-md-2">@sortablelink('domain', trans('companies.domain'))</th>
<th class="col-md-2">@sortablelink('email', trans('general.email'))</th>
<th class="col-md-3">{{ trans('general.actions') }}</th>
</tr>
</thead>
<tbody>
Expand All @@ -46,6 +45,7 @@
<td>{{ $item->domain }}</td>
<td>{{ $item->company_email }}</td>
<td>
<a href="{{ url('companies/companies/' . $item->id . '/set') }}" class="btn btn-info btn-xs"><i class="fa fa-arrow-right" aria-hidden="true"></i> {{ trans('general.change') }}</a>
<a href="{{ url('companies/companies/' . $item->id . '/edit') }}" class="btn btn-primary btn-xs"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> {{ trans('general.edit') }}</a>
@permission('delete-companies-companies')
{!! Form::deleteButton($item, 'companies/companies', '', 'company_name') !!}
Expand All @@ -58,6 +58,11 @@
</div>
</div>
<!-- /.box-body -->

<div class="box-footer">
@include('partials.admin.pagination', ['items' => $companies, 'type' => 'companies'])
</div>
<!-- /.box-footer -->
</div>
<!-- /.box -->
@endsection
Expand Down

0 comments on commit d4320ab

Please sign in to comment.