journal-intime/app/Http/Controllers/HomeController.php
Shikiryu 9dc50d6130 🎉 Hello world
2019-09-18 16:50:01 +02:00

56 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
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()
{
setlocale(LC_TIME, 'fr_FR.utf8');
$today = new \DateTime();
$posts = \App\Post::where('user_id', Auth::user()->getAuthIdentifier())->get();
return view('home', [
'today' => $today,
'posts' => $posts,
]);
}
public function store()
{
$data = request()->validate([
'message' => 'required'
]);
$data = [
'user_id' => Auth::user()->getAuthIdentifier(),
'date_post' => new \DateTime(), // Take back the date from the form ?
'content' => $data['message'],
];
$check = \App\Post::create($data);
return Redirect::to('home')->withSuccess('Great! Form successfully submit with validation.');
}
}