95 lines
2.0 KiB
PHP
95 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\User;
|
|
|
|
use App\Models\Contact;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class UserContactController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$contacts = Contact::where('pemilik_kontak',Auth::user()->email);
|
|
return view('user.contact.index',['contacts'=>$contacts]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$result = Contact::create([
|
|
'pemilik_kontak' => Auth::user()->email,
|
|
'relasi_kontak' => $request->relasi_kontak,
|
|
]);
|
|
|
|
if($result){
|
|
return response()->json([
|
|
'status' => true,
|
|
'message' => $result,
|
|
]);
|
|
}else{
|
|
return response()->json([
|
|
'status' => false,
|
|
'message' => $result,
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(Contact $contact)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(Contact $contact)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, Contact $contact)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(Contact $contact, $id)
|
|
{
|
|
try{
|
|
Contact::destroy($id);
|
|
return response()->json([
|
|
'message' => 'Berhasil hapus data',
|
|
'status' => true
|
|
]);
|
|
}catch(\Exception $e){
|
|
return response()->json([
|
|
'message' => 'Gagal hapus data, karena '.$e,
|
|
'status' => false
|
|
]);
|
|
}
|
|
}
|
|
}
|