Skip to content

Commit

Permalink
fixed #118
Browse files Browse the repository at this point in the history
  • Loading branch information
jhuebel committed Jul 3, 2019
1 parent 406ad2b commit 4e08be7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
8 changes: 4 additions & 4 deletions app/Http/Controllers/ClientsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Datatables;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class ClientsController extends Controller
{
Expand Down Expand Up @@ -53,17 +54,16 @@ public function my()
*/
public function anyData()
{
$clients = Client::with('user')->select('clients.*');
$clients = Client::select(['clients.*', DB::raw('users.name AS salesperson')])->join('users', 'clients.user_id', '=', 'users.id');

// $clients = Client::with('user')->select('clients.*');

$dt = Datatables::of($clients)
->addColumn('namelink', function ($clients) {
return '<a href="clients/'.$clients->id.'">'.$clients->name.'</a>';
})
->addColumn('emaillink', function ($clients) {
return '<a href="mailto:'.$clients->primary_email.'">'.$clients->primary_email.'</a>';
})
->addColumn('salesperson', function ($clients) {
return $clients->user->name;
});

// this looks wierd, but in order to keep the two buttons on the same line
Expand Down
12 changes: 4 additions & 8 deletions app/Http/Controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Datatables;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class ContactsController extends Controller
{
Expand Down Expand Up @@ -57,15 +58,13 @@ public function my()
*/
public function anyData()
{
$contacts = Contact::with('client')->select('contacts.*');
$contacts = Contact::select(['contacts.*', DB::raw('clients.name AS client_name')])->join('clients', 'contacts.client_id', '=', 'clients.id');
// $contacts = Contact::with('client')->select('contacts.*');

$dt = Datatables::of($contacts)
->addColumn('namelink', function ($contacts) {
return '<a href="'.route('contacts.show', $contacts->id).'">'.$contacts->name.'</a>';
})
->addColumn('client_name', function ($contacts) {
return $contacts->client->name;
})
->addColumn('emaillink', function ($contacts) {
return '<a href="mailto:'.$contacts->email.'">'.$contacts->email.'</a>';
});
Expand Down Expand Up @@ -99,15 +98,12 @@ public function anyData()
*/
public function myData()
{
$contacts = Contact::with('client')->select('contacts.*')->my();
$contacts = Contact::select(['contacts.*', DB::raw('clients.name AS client_name')])->join('clients', 'contacts.client_id', '=', 'clients.id')->my();

$dt = Datatables::of($contacts)
->addColumn('namelink', function ($contacts) {
return '<a href="contacts/'.$contacts->id.'">'.$contacts->name.'</a>';
})
->addColumn('client_name', function ($contacts) {
return $contacts->client->name;
})
->addColumn('emaillink', function ($contacts) {
return '<a href="mailto:'.$contacts->email.'">'.$contacts->email.'</a>';
});
Expand Down

0 comments on commit 4e08be7

Please sign in to comment.