datatable.directory codebase https://datatable.directory/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
datatable.directory/app/Http/Controllers/ProfileController.php

93 lines
2.2 KiB

<?php
namespace App\Http\Controllers;
use App\Models\Table;
use App\Models\User;
6 years ago
use Illuminate\Http\Request;
6 years ago
/**
* Profile page and profile settings
*/
class ProfileController extends Controller
{
private function profileTableListPrepareData(User $user)
{
$data['user'] = $user;
$data['tables_count'] = $user->tables()->count();
$data['favourites_count'] = $user->favouriteTables()->count();
$data['tableSort'] = Table::resolveSortType(\Input::get('tableSort'));
$data['sortOptions'] = Table::getSortOptions();
return $data;
}
/**
6 years ago
* Show the user's profile / dashboard.
*
* @return \Illuminate\View\View
*/
public function view(User $user)
{
$data = $this->profileTableListPrepareData($user);
$data['pageVariant'] = 'tables';
$data['tables'] = $user->tables()->forList()
->tableSort($data['tableSort'])
->paginate(10);
return view('profile.view', $data);
}
/**
* Show the user's profile / dashboard.
*
* @return \Illuminate\View\View
*/
public function viewFavourites(User $user)
{
$data = $this->profileTableListPrepareData($user);
$data['pageVariant'] = 'favourites';
$data['tables'] = $user->favouriteTables()->forList()
->tableSort($data['tableSort'])
->paginate(10);
$data['showAuthors'] = true;
return view('profile.view', $data);
}
/**
* Edit own profile (this does not include auth settings etc)
*
* @return \Illuminate\View\View
*/
public function editProfile()
{
return view('profile.edit-profile')->with('user', \user());
}
6 years ago
/**
* Store changed profile
*/
public function storeProfile(Request $request)
{
$input = $this->validate($request, [
'title' => ['required', VALI_LINE],
6 years ago
'bio' => ['nullable', VALI_TEXT],
'website' => ['nullable', VALI_LINE],
]);
$user = user();
$user->fill($input->all());
$user->save();
flash()->success('Settings saved');
return back();
}
}