From 5412e1aa50a46c178782efccffa73e61fe7782de Mon Sep 17 00:00:00 2001 From: Aqeeb Imtiaz Harun Date: Mon, 2 Jul 2018 10:50:20 +0800 Subject: [PATCH] Added listing of Contacts frontend --- app/Company.php | 10 +- app/Contact.php | 6 +- app/Http/Controllers/ContactController.php | 13 +- public/contacts.html | 261 +++++++-------------- routes/api.php | 6 +- 5 files changed, 102 insertions(+), 194 deletions(-) diff --git a/app/Company.php b/app/Company.php index 99937c0..9f119af 100644 --- a/app/Company.php +++ b/app/Company.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; class Company extends Model { - + protected $fillable = ['user_id', 'company_profile', 'reg_cert', 'company_name', 'registration_no', 'tax_no', 'tel_no', 'fax', 'address', 'city', 'postcode', 'state', 'country', 'contact_person']; public function user() @@ -17,18 +17,18 @@ class Company extends Model public function deliveryinfo() { return $this->hasMany('App\Deliveryinfo'); - + } public function warehouse() { return $this->hasMany('App\Warehouse'); - + } - public function contact() { + public function contacts() { return $this->hasMany('App\Contact'); - + } } diff --git a/app/Contact.php b/app/Contact.php index fdc4610..8a0a010 100644 --- a/app/Contact.php +++ b/app/Contact.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; class Contact extends Model { - protected $fillable = ['company_id']; + protected $fillable = ['com_id']; public function user() { @@ -14,9 +14,9 @@ class Contact extends Model } - public function company(){ + public function companies(){ - return $this->belongsTo(App/Company); + return $this->belongsTo('App\Company'); } diff --git a/app/Http/Controllers/ContactController.php b/app/Http/Controllers/ContactController.php index 63570b3..20ccfc0 100644 --- a/app/Http/Controllers/ContactController.php +++ b/app/Http/Controllers/ContactController.php @@ -11,14 +11,23 @@ class ContactController extends Controller { public function index() { - $contacts = Contact::where('user_id', Auth::user()->id)->where('id', $id)->get(); + $output= array(); + $contacts = Contact::where('user_id', Auth::user()->id)->get(); + $companies= Contact::with('companies')->get(); + //$companies =\DB::table('companies')->select('contacts.com_id', 'companies.id', 'companies.company_name')->join('contacts', 'contacts.com_id', '=', 'companies.id')->get(); + //$companies = "SELECT contacts.com_id, companies.id, companies.company_name FROM `companies` INNER JOIN contacts ON contacts.com_id = companies.id"; + + // $companies = \DB::table('companies') + // ->select('id', 'company_name') + // ->where('com_id', Auth::user()->id) + // ->get(); if (!$contacts) { return response()->json(['message'=>'Access Denied!'], 404); } - return response()->json($contacts, 200); + return response()->json($companies, 200); } public function sendRequest(Request $request) diff --git a/public/contacts.html b/public/contacts.html index 7ad89f1..2a1d5ce 100644 --- a/public/contacts.html +++ b/public/contacts.html @@ -11,199 +11,71 @@ - -
-

Contacts

-
-
- - -
@@ -219,7 +91,7 @@