56 lines
1.3 KiB
PHP
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.');
|
||
|
}
|
||
|
}
|