61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Bo;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Models\Contact;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Illuminate\Support\Facades\Cache;
|
||
|
|
use Illuminate\Support\Facades\Storage;
|
||
|
|
|
||
|
|
class ContactController extends Controller
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Display a listing of the resource.
|
||
|
|
*
|
||
|
|
* @param \Illuminate\Http\Request $request
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function index(Request $request)
|
||
|
|
{
|
||
|
|
/** @var \Illuminate\Database\Eloquent\Builder $contacts */
|
||
|
|
$contacts = Contact::query();
|
||
|
|
|
||
|
|
/** @var string $search Search field */
|
||
|
|
if ($request->search) {
|
||
|
|
$this->searchQuery(
|
||
|
|
$contacts,
|
||
|
|
$request->search,
|
||
|
|
null,
|
||
|
|
'firstname',
|
||
|
|
'lastname',
|
||
|
|
'email',
|
||
|
|
);
|
||
|
|
}
|
||
|
|
$searchFields = \implode(',', [trans('Nom'), trans('Prénom'), trans('Email')]);
|
||
|
|
|
||
|
|
/** Sort columns with a query */
|
||
|
|
$this->sortQuery($contacts);
|
||
|
|
|
||
|
|
/** @var integer $pagination Items per page */
|
||
|
|
if ($request->pagination) {
|
||
|
|
// FIXME: Add pagination validation.
|
||
|
|
Cache::forever('pagination', intval($request->pagination));
|
||
|
|
}
|
||
|
|
$contactModelList = $contacts->paginate(intval(Cache::get('pagination')) ?? config('pagination.default'));
|
||
|
|
|
||
|
|
return view('bo.pages.contacts.index', compact('contactModelList', 'searchFields'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Display the specified resource.
|
||
|
|
*
|
||
|
|
* @param \App\Models\Contact $contact
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function show(Contact $contact)
|
||
|
|
{
|
||
|
|
return \view('bo.pages.contacts.show', ['contactModel' => $contact]);
|
||
|
|
}
|
||
|
|
}
|