mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim-api.git
synced 2026-08-19 04:24:01 +00:00
Merge branch 'asif/contact' of gitlab.com:CIEFWorldwideSdnBhd/izyim-api into asif/warehouses
# Conflicts: # app/Http/Controllers/CompanyController.php # package-lock.json # routes/api.php
This commit is contained in:
@@ -10,6 +10,12 @@ 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'];
|
||||
//protected $guarded = [];
|
||||
|
||||
|
||||
public function Contact()
|
||||
|
||||
{
|
||||
return $this->hasMany(Contact::class);
|
||||
}
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\User');
|
||||
|
||||
+21
-1
@@ -6,5 +6,25 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Contact extends Model
|
||||
{
|
||||
protected $fillable = ['user_id','company_id'];
|
||||
protected $fillable = ['company_id'];
|
||||
|
||||
|
||||
|
||||
public function User()
|
||||
|
||||
{
|
||||
|
||||
return $this->belongsTo(User::class);
|
||||
|
||||
}
|
||||
public function Company()
|
||||
|
||||
{
|
||||
|
||||
return $this->belongsTo(Company::class);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,28 @@ use Auth;
|
||||
|
||||
class CompanyController extends Controller
|
||||
{
|
||||
public function search(Request $request)
|
||||
{
|
||||
if($request->search == ''){
|
||||
return '';
|
||||
}
|
||||
$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,
|
||||
'contact_person'=>$matchedTerm->contact_person ]);
|
||||
}
|
||||
|
||||
return response($output);
|
||||
}
|
||||
else{return "error";}
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$company = Company::where("user_id", Auth::user()->id)->first();
|
||||
|
||||
@@ -3,120 +3,79 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Contact;
|
||||
use App\Company;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ContactController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$contact=Contact::all();
|
||||
$response=[
|
||||
|
||||
'contact'=>$contact
|
||||
|
||||
];
|
||||
return response()->json($contact, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// get company id from request ex: $request->input('company_id')
|
||||
// $company_id = $request->input('company_id'))
|
||||
// get company id from request ex:
|
||||
//$request->input('company_id');
|
||||
$company_id = $request->input('company_id');
|
||||
// query to find company asisng to $company
|
||||
$company = Company::find($company_id);
|
||||
|
||||
// query to find company asisng to $company
|
||||
// $company = Comapny::find($company_id)
|
||||
|
||||
// get user from session $request->user();
|
||||
// $user = $request->user();
|
||||
// get user from session
|
||||
//$request->user();
|
||||
$user = $request->user();
|
||||
|
||||
// prepare query
|
||||
|
||||
|
||||
$contact = new Contact();
|
||||
$contact->company_id = $company->id;
|
||||
$contact->user_id = $user->id;
|
||||
$contact->save();
|
||||
// insert into database
|
||||
|
||||
|
||||
return response()->json($contact, 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
// $contact = Contact::find($id);
|
||||
// if (!$contact)
|
||||
// {
|
||||
// return response()->json(['message'=>'ID not found'],200);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// $contact->ff_id=$request->input('ff_id');
|
||||
//
|
||||
//
|
||||
// $contact->save();
|
||||
// return response()->json(['contact'=>$contact],200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$contact=Contact::find($id);
|
||||
$contact = Contact::where("user_id", Auth::user()->id)->where('id', $id)->first();
|
||||
//$contact=Contact::find($id);
|
||||
$contact->delete();
|
||||
|
||||
return response()->json($contact, 204);
|
||||
}
|
||||
|
||||
public function postApprove(Request $request, $id)
|
||||
{
|
||||
$contact = Contact::where("user_id", Auth::user()->id)->where('id', $id)->first();
|
||||
//$contact = Contact::where('id', '=', e($id))->first();
|
||||
if($contact)
|
||||
{
|
||||
$action=$request->input('action');
|
||||
if ($action==1)
|
||||
{
|
||||
$contact->status=1;
|
||||
}
|
||||
if ($action==0)
|
||||
{
|
||||
$contact->status=0;
|
||||
}
|
||||
else{
|
||||
return response()->json(["message" => "not allowed"], 400);
|
||||
}
|
||||
|
||||
$saved = $contact->save();
|
||||
if ($saved){
|
||||
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 ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Contact;
|
||||
use App\Warehouse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -111,5 +112,6 @@ class WarehouseController extends Controller
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user