R from CRUD
This commit is contained in:
parent
5d46844f95
commit
34b7c21e48
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
Reference in a new issue