bug fixing

This commit is contained in:
Zain Fauzan Rofie Azizi
2018-06-25 09:38:03 +08:00
parent 7d51085dae
commit 48e033f436
7 changed files with 133 additions and 47 deletions
+57 -29
View File
@@ -8,52 +8,59 @@ use Illuminate\Http\Request;
class ContactController extends Controller
{
/**
* list the company that belongs to user's company only
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function index()
{
$contact=Contact::all();
$response=[
'contact'=>$contact
];
return response()->json($contact, 200);
$contacts = Contact::where('user_id', Auth::user()->id)->where('id', $id)->first();
if (!$contacts)
{
return response()->json(['message'=>'Access Denied!'], 404);
}
return response()->json($contacts, 200);
}
/**
* Store a new contact list.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$user = Auth::user();
$contact = new Contact;
$contact->com_id = $user->company();
// get company id from request ex:
// query to find company asisng to $company
// $company = Company::find($company_id);
$company = Company::find($com_id);
// get user from session
// $request->user();
// $user = $request->user();
$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
$contact = new Contact();
$contact->com_id = $company->id;
$contact->user_id = $user->id;
$contact->save();
return response()->json($contact, 201);
}
public function destroy($id)
{
$contact = Contact::where("user_id", Auth::user()->id)->where('id', $id)->first();
//$contact=Contact::find($id);
$contact->delete();
return response()->json($contact, 204);
}
/**
* Approve a new contact list.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function postApprove(Request $request, $id)
{
$contact = Contact::where("user_id", Auth::user()->id)->where('id', $id)->first();
$contact = Contact::where('com_id', Auth::user()->company())->where('id', $id)->first();
//$contact = Contact::where('id', '=', e($id))->first();
if($contact)
{
@@ -67,6 +74,7 @@ class ContactController extends Controller
$contact->status=0;
}
else{
return response()->json(["message" => "not allowed"], 400);
}
@@ -82,4 +90,24 @@ class ContactController extends Controller
//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();
if (!$contact)
{
return response()->json(['message'=>'Access Denied!'], 404);
}
$contact->delete($id);
return response()->json($contact, 204);
}
}