2016-05-19 15:01:28 +01:00
|
|
|
<?php
|
|
|
|
|
2018-01-15 14:02:13 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-05-19 15:01:28 +01:00
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2017-12-19 16:00:42 +00:00
|
|
|
use App\Models\Contact;
|
2016-05-19 15:01:28 +01:00
|
|
|
use Illuminate\Filesystem\Filesystem;
|
2019-10-27 16:29:15 +00:00
|
|
|
use Illuminate\View\View;
|
2016-05-19 15:01:28 +01:00
|
|
|
|
|
|
|
class ContactsController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Show all the contacts.
|
|
|
|
*
|
2020-08-09 15:54:10 +01:00
|
|
|
* @return View
|
2016-05-19 15:01:28 +01:00
|
|
|
*/
|
2018-01-15 14:02:13 +00:00
|
|
|
public function index(): View
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
|
|
|
$filesystem = new Filesystem();
|
|
|
|
$contacts = Contact::all();
|
|
|
|
foreach ($contacts as $contact) {
|
2016-11-25 15:53:14 +00:00
|
|
|
$contact->homepageHost = parse_url($contact->homepage, PHP_URL_HOST);
|
|
|
|
$file = public_path() . '/assets/profile-images/' . $contact->homepageHost . '/image';
|
2016-05-19 15:01:28 +01:00
|
|
|
$contact->image = ($filesystem->exists($file)) ?
|
2016-11-25 15:53:14 +00:00
|
|
|
'/assets/profile-images/' . $contact->homepageHost . '/image'
|
2016-05-19 15:01:28 +01:00
|
|
|
:
|
|
|
|
'/assets/profile-images/default-image';
|
|
|
|
}
|
|
|
|
|
2017-02-15 18:41:54 +00:00
|
|
|
return view('contacts.index', compact('contacts'));
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a single contact.
|
|
|
|
*
|
2022-07-09 10:08:26 +01:00
|
|
|
* @param Contact $contact
|
2020-08-09 15:54:10 +01:00
|
|
|
* @return View
|
2016-05-19 15:01:28 +01:00
|
|
|
*/
|
2020-08-09 15:54:10 +01:00
|
|
|
public function show(Contact $contact): View
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
2016-11-25 15:53:14 +00:00
|
|
|
$contact->homepageHost = parse_url($contact->homepage, PHP_URL_HOST);
|
|
|
|
$file = public_path() . '/assets/profile-images/' . $contact->homepageHost . '/image';
|
2020-08-09 15:54:10 +01:00
|
|
|
|
|
|
|
$filesystem = new Filesystem();
|
2017-02-18 14:16:22 +00:00
|
|
|
$image = ($filesystem->exists($file)) ?
|
2016-11-25 15:53:14 +00:00
|
|
|
'/assets/profile-images/' . $contact->homepageHost . '/image'
|
2016-05-19 15:01:28 +01:00
|
|
|
:
|
|
|
|
'/assets/profile-images/default-image';
|
|
|
|
|
2017-02-18 14:16:22 +00:00
|
|
|
return view('contacts.show', compact('contact', 'image'));
|
2016-05-19 15:01:28 +01:00
|
|
|
}
|
|
|
|
}
|