🎨 Empêche 2 posts par jour et améliore l'affichage

This commit is contained in:
Shikiryu
2019-09-25 15:20:22 +02:00
parent 31dc160ada
commit e6527a72af
6 changed files with 82 additions and 105 deletions

View File

@@ -2,7 +2,8 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
use DateTime;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
@@ -26,11 +27,20 @@ class HomeController extends Controller
public function index()
{
setlocale(LC_TIME, 'fr_FR.utf8');
$today = new \DateTime();
$today = new DateTime();
$user_id = Auth::user()->getAuthIdentifier();
$posts = Post::where('user_id', $user_id)->orderBy('date_post', 'DESC')->get();
$today_post = Post::whereDate('date_post', '=', $today->format('Y-m-d'))
->where('user_id', $user_id)
->count();
$posts = \App\Post::where('user_id', Auth::user()->getAuthIdentifier())->get();
$already = false;
if ($today_post > 0) {
$already = true;
}
return view('home', [
'already' => $already,
'today' => $today,
'posts' => $posts,
]);
@@ -38,17 +48,19 @@ class HomeController extends Controller
public function store()
{
$today = new DateTime();
$data = request()->validate([
'message' => 'required'
]);
$data = [
'user_id' => Auth::user()->getAuthIdentifier(),
'date_post' => new \DateTime(), // Take back the date from the form ?
'date_post' => new DateTime(), // Take back the date from the form ?
'content' => $data['message'],
];
$check = \App\Post::create($data);
$check = Post::create($data);
return Redirect::to('home')->withSuccess('Great! Form successfully submit with validation.');
}