R from CRUD

This commit is contained in:
Alexander Yakovlev 2020-03-05 22:25:36 +07:00
parent 5d46844f95
commit 34b7c21e48
Signed by: oreolek
GPG key ID: 1CDC4B7820C93BD3
3 changed files with 20 additions and 7 deletions

View file

@ -30,4 +30,15 @@ class Diary extends Model
->where('day', $day)
->exists();
}
public static function addRecord($mood_id) {
if (self::votedToday()) {
return;
}
$model = new Diary();
$model->user_id = Auth::id();
$model->mood_id = (int) $mood_id;
$model->day = date('Y-m-d');
$model->save();
}
}

View file

@ -35,15 +35,15 @@ class HomeController extends Controller
]);
}
if (!empty($mood)) {
$model = new Diary();
$model->user_id = Auth::id();
$model->mood_id = (int) $mood;
$model->day = date('Y-m-d');
$model->save();
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
'moods' => $moods,
'history' => $history
]);
}
}

View file

@ -14,7 +14,9 @@
</div>
@endif
You are logged in!
@foreach($history as $record)
<img type="image/svg+xml" src="/emoji/{{ $record->mood->codepoint }}.svg" alt="@lang('app.'.$record->mood->name)" width="64" height="64">
@endforeach
</div>
</div>
</div>