Ekapp/skolehjem/app/Http/Controllers/ContactController.php

114 lines
2.6 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Contact;
class ContactController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$contact = Contact::query()->paginate($request->input("limit", 20));
return Response::detect("contacts.index", [ "contacts" => $contact]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return Response::detect("contacts.create");
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$requestContact = $request->validate([
"name_first" => "required|max:255",
"name_last" => "required|max:255",
"email" => "required|max:255",
"phone" => "required|max:255",
]);
$contact = new Contact($requestContact);
$contact->save();
return Response::detect("contacts.store");
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
return Response::detect("contacts.show", [ "contacts" => $id]);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$contacts = Contact::find($id);
return Response::detect("contacts.edit", ["contact" => $contacts]);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$data = $request->all();
//FORCED UPDATE
$contact = Contact::find($id);
$contact->update($data);
$contact->save();
return Response::detect("contacts.update", [ "contact" => $contact ]);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$contact = Contact::find($id);
$contact->delete();
return redirect()->route("contacts.index");
}
}