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-06-29 06:50:50 +00:00
|
|
|
|
|
|
|
class ContactController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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-06-29 08:07:42 +00:00
|
|
|
|
|
|
|
$contact = Contact::query()->paginate($request->input("limit", 20));
|
|
|
|
|
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-06-29 08:37:37 +00:00
|
|
|
"name_first" => "required|max:255",
|
|
|
|
"name_last" => "required|max:255",
|
|
|
|
"email" => "required|max:255",
|
2020-06-29 09:14:07 +00:00
|
|
|
"phone" => "required|max:255",
|
2020-06-29 08:30:09 +00:00
|
|
|
]);
|
|
|
|
|
2020-06-29 08:41:27 +00:00
|
|
|
$contact = new Contact($requestContact);
|
2020-06-29 08:30:09 +00:00
|
|
|
$contact->save();
|
|
|
|
|
|
|
|
return Response::detect("contacts.store");
|
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 09:48:36 +00:00
|
|
|
$contacts = Contact::find($id);
|
|
|
|
return Response::detect("contacts.edit", ["contact" => $contacts]);
|
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);
|
|
|
|
$contact->save();
|
|
|
|
|
2020-06-29 10:21:16 +00:00
|
|
|
return Response::detect("contacts.update", [ "contacts" => $contact ]);
|
2020-06-29 06:50:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
2020-06-29 09:48:36 +00:00
|
|
|
|
|
|
|
$contact = Contact::find($id);
|
|
|
|
$contact->delete();
|
|
|
|
return redirect()->route("contacts.index");
|
2020-06-29 06:50:50 +00:00
|
|
|
}
|
|
|
|
}
|