2016-05-19 15:01:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Contact;
|
|
|
|
use Illuminate\Filesystem\Filesystem;
|
|
|
|
|
|
|
|
class ContactsController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Show all the contacts.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\Factory view
|
|
|
|
*/
|
2017-02-15 18:41:54 +00:00
|
|
|
public function index()
|
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.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\View\Factory view
|
|
|
|
*/
|
2017-02-15 18:41:54 +00:00
|
|
|
public function show($nick)
|
2016-05-19 15:01:28 +01:00
|
|
|
{
|
|
|
|
$filesystem = new Filesystem();
|
|
|
|
$contact = Contact::where('nick', '=', $nick)->firstOrFail();
|
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';
|
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
|
|
|
}
|
|
|
|
}
|