This repository has been archived on 2024-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
notdepressed/app/Http/Controllers/HomeController.php
2020-03-05 22:25:36 +07:00

50 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use App\Mood;
use App\Diary;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index(Request $request)
{
$votedToday = Diary::votedToday();
$moods = Mood::all();
$mood = $request->input('mood');
if (!$votedToday && empty($mood)) {
return view('new_record', [
'moods' => $moods
]);
}
if (!empty($mood)) {
Diary::addRecord($mood);
$request->session()->flash('status', __('Logged your mood.'));
// Clear GET parameters.
return redirect('/home');
}
$history = Diary::with('mood')->where('user_id', Auth::id())->where('created_at', '>', strtotime('-1 year'))->get();
return view('home', [
'moods' => $moods,
'history' => $history
]);
}
}