diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 0377374..6678458 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -17,13 +17,12 @@ class CompanyController extends Controller } $output= array(); $matchedTerms = Company::where('company_name', 'LIKE','%'. $request->search . '%')->get(); - //return response()->json($matchedTerm); if($matchedTerms) { foreach ($matchedTerms as $key => $matchedTerm) { - array_push($output, ['company_name' => $matchedTerm->company_name, 'tel_no' => $matchedTerm->tel_no, + array_push($output, ['com_id'=> $matchedTerm->id, 'company_name' => $matchedTerm->company_name, 'tel_no' => $matchedTerm->tel_no, 'contact_person'=>$matchedTerm->contact_person ]); } @@ -62,14 +61,8 @@ class CompanyController extends Controller } } - /** - * Show the form for creating a new resource. - * - * @return \Illuminate\Http\Response - */ public function create() { - // $company->company_name=$request->input('company_name'); $company->registration_no=$request->input('registration_no'); $company->tax_no=$request->input('tax_no'); diff --git a/app/Http/Controllers/ContactController.php b/app/Http/Controllers/ContactController.php index 26530e9..63570b3 100644 --- a/app/Http/Controllers/ContactController.php +++ b/app/Http/Controllers/ContactController.php @@ -5,15 +5,10 @@ namespace App\Http\Controllers; use App\Contact; use App\Company; use Illuminate\Http\Request; +use Auth; class ContactController extends Controller { - /** - * - * - * @param int $id - * @return \Illuminate\Http\Response - */ public function index() { $contacts = Contact::where('user_id', Auth::user()->id)->where('id', $id)->get(); @@ -26,16 +21,11 @@ class ContactController extends Controller return response()->json($contacts, 200); } - /** - * Store a new contact list. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response - */ - public function store(Request $request) + public function sendRequest(Request $request) { $user = Auth::user(); - + $com_id = $request->input('com_id'); + // query to find company asisng to $company $company = Company::find($com_id); @@ -48,17 +38,11 @@ class ContactController extends Controller $contact->com_id = $company->id; $contact->user_id = $user->id; $contact->save(); - + return response()->json($contact, 201); } - /** - * Approve a new contact list. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response - */ - public function postApprove(Request $request, $id) + public function acceptRequest(Request $request, $id) { $contact = Contact::where('com_id', Auth::user()->company())->where('id', $id)->first(); //$contact = Contact::where('id', '=', e($id))->first(); @@ -74,7 +58,7 @@ class ContactController extends Controller $contact->status=0; } else{ - + return response()->json(["message" => "not allowed"], 400); } @@ -83,20 +67,9 @@ class ContactController extends Controller return response()->json($contact, 201); } return response()->json($contact, 400); - -// $contact = $request->input('id'); -// $contact->status = 1; -// $contact->save(); - //return redirect()->back()->with('info','Request has been approved '); } } - /** - * Remove the contact list. - * - * @param int $id - * @return \Illuminate\Http\Response - */ public function destroy($id) { $contact = Contact::where('com_id', Auth::user()->company())->where('id', $id)->first(); diff --git a/database/migrations/2018_06_22_072528_add_foreign_key_to_warehouses_table.php b/database/migrations/2018_06_22_072528_add_foreign_key_to_warehouses_table.php index 5be85d8..f616313 100644 --- a/database/migrations/2018_06_22_072528_add_foreign_key_to_warehouses_table.php +++ b/database/migrations/2018_06_22_072528_add_foreign_key_to_warehouses_table.php @@ -14,12 +14,11 @@ class AddForeignKeyToWarehousesTable extends Migration public function up() { Schema::table('warehouses', function (Blueprint $table) { - + $table->unsignedInteger('com_id');//FK wrn id $table->foreign('com_id') ->references('id')->on('warehouses') ->onDelete('cascade'); - }); } @@ -33,6 +32,7 @@ class AddForeignKeyToWarehousesTable extends Migration { Schema::table('warehouses', function (Blueprint $table) { // + }); } } diff --git a/database/migrations/2018_06_26_075427_drop_and_add_company_id.php b/database/migrations/2018_06_26_075427_drop_and_add_company_id.php new file mode 100644 index 0000000..3de1f04 --- /dev/null +++ b/database/migrations/2018_06_26_075427_drop_and_add_company_id.php @@ -0,0 +1,33 @@ +renameColumn('company_id', 'com_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('contacts', function (Blueprint $table) { + $table->renameColumn('com_id', 'company_id'); + }); + } +} diff --git a/database/migrations/2018_06_26_080331_drop_company_id.php b/database/migrations/2018_06_26_080331_drop_company_id.php new file mode 100644 index 0000000..ee510bc --- /dev/null +++ b/database/migrations/2018_06_26_080331_drop_company_id.php @@ -0,0 +1,32 @@ +dropColumn('company_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('warehouses', function (Blueprint $table) { + // + }); + } +} diff --git a/public/search-contact.html b/public/search-contact.html index f04626f..26a1f6b 100644 --- a/public/search-contact.html +++ b/public/search-contact.html @@ -62,7 +62,7 @@
-