2020-06-29 06:50:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
2020-06-29 08:07:42 +00:00
|
|
|
use Illuminate\Http\Response;
|
|
|
|
use App\Contact;
|
2020-07-07 17:29:21 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2020-07-01 07:50:37 +00:00
|
|
|
use phpDocumentor\Reflection\Types\Context;
|
2020-07-27 11:24:35 +00:00
|
|
|
|
2020-06-29 06:50:50 +00:00
|
|
|
class ContactController extends Controller
|
|
|
|
{
|
2020-06-30 07:21:21 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware([ "auth" ]);
|
2020-08-06 13:31:38 +00:00
|
|
|
$this->middleware([ "lang" ]);
|
2020-06-30 07:21:21 +00:00
|
|
|
|
2020-08-31 07:36:10 +00:00
|
|
|
$this->middleware([ "check.auth:contact.show" ])->only("show", "index");
|
2020-06-30 07:21:21 +00:00
|
|
|
$this->middleware([ "check.auth:contact.create" ])->only("create", "store");
|
|
|
|
$this->middleware([ "check.auth:contact.edit" ])->only("edit", "update");
|
|
|
|
$this->middleware([ "check.auth:contact.delete" ])->only("delete");
|
|
|
|
}
|
|
|
|
|
2020-06-29 06:50:50 +00:00
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-06-29 08:07:42 +00:00
|
|
|
public function index(Request $request)
|
2020-06-29 06:50:50 +00:00
|
|
|
{
|
2020-09-18 08:04:33 +00:00
|
|
|
$contact = Contact::query()->get();
|
2020-06-29 08:07:42 +00:00
|
|
|
|
2020-06-29 09:39:00 +00:00
|
|
|
return Response::detect("contacts.index", [ "contacts" => $contact]);
|
2020-06-29 06:50:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2020-06-29 08:41:27 +00:00
|
|
|
return Response::detect("contacts.create");
|
2020-06-29 08:30:09 +00:00
|
|
|
|
2020-06-29 06:50:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2020-06-29 08:30:09 +00:00
|
|
|
$requestContact = $request->validate([
|
2020-07-27 11:34:45 +00:00
|
|
|
"contactname" => "required|max:255",
|
|
|
|
"title" => "required|max:255",
|
2020-06-29 08:37:37 +00:00
|
|
|
"email" => "required|max:255",
|
2020-08-05 11:29:45 +00:00
|
|
|
"phone" => "max:255",
|
2020-06-29 08:30:09 +00:00
|
|
|
]);
|
|
|
|
|
2020-06-29 08:41:27 +00:00
|
|
|
$contact = new Contact($requestContact);
|
2020-08-05 07:43:53 +00:00
|
|
|
$contact->phonetimes = $request->phonetimes;
|
2020-07-01 07:50:37 +00:00
|
|
|
$saved = $contact->save();
|
|
|
|
|
|
|
|
if(!$saved){
|
2020-08-05 07:43:53 +00:00
|
|
|
return redirect()->route("contacts.store");
|
2020-07-01 07:50:37 +00:00
|
|
|
}else{
|
2020-09-22 08:45:27 +00:00
|
|
|
$contact = Contact::query()->get();
|
2020-08-05 07:43:53 +00:00
|
|
|
return redirect()->route("contacts.index", ['contacts' => $contact]);
|
2020-07-01 07:50:37 +00:00
|
|
|
}
|
2020-06-29 08:30:09 +00:00
|
|
|
|
2020-06-29 06:50:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
2020-06-29 09:48:36 +00:00
|
|
|
return Response::detect("contacts.show", [ "contacts" => $id]);
|
|
|
|
|
2020-06-29 06:50:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
2020-06-29 10:36:07 +00:00
|
|
|
$contact = Contact::find($id);
|
|
|
|
return Response::detect("contacts.edit", ["contact" => $contact]);
|
2020-06-29 06:50:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
{
|
2020-06-29 09:48:36 +00:00
|
|
|
|
|
|
|
$data = $request->all();
|
|
|
|
$contact = Contact::find($id);
|
|
|
|
$contact->update($data);
|
2020-07-01 07:50:37 +00:00
|
|
|
$saved = $contact->save();
|
|
|
|
|
|
|
|
if(!$saved){
|
2020-08-05 07:43:53 +00:00
|
|
|
return redirect()->route("contacts.update", [ "contacts" => $contact ]);
|
2020-07-01 07:50:37 +00:00
|
|
|
}else{
|
2020-09-22 08:45:27 +00:00
|
|
|
$contact = Contact::query()->get();
|
2020-08-05 07:43:53 +00:00
|
|
|
return redirect()->route("contacts.index", ['contacts' => $contact]);
|
2020-07-01 07:50:37 +00:00
|
|
|
}
|
2020-06-29 09:48:36 +00:00
|
|
|
|
2020-06-29 06:50:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2020-06-29 11:18:58 +00:00
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
* @throws \Exception
|
2020-06-29 06:50:50 +00:00
|
|
|
*/
|
2020-06-30 09:45:54 +00:00
|
|
|
public function destroy($id)
|
2020-06-29 06:50:50 +00:00
|
|
|
{
|
2020-06-30 09:45:54 +00:00
|
|
|
$contact = Contact::find($id);
|
|
|
|
$contact->delete();
|
2020-06-29 09:48:36 +00:00
|
|
|
return redirect()->route("contacts.index");
|
2020-06-29 06:50:50 +00:00
|
|
|
}
|
|
|
|
}
|