🎉 Hello world
This commit is contained in:
55
app/Http/Controllers/HomeController.php
Normal file
55
app/Http/Controllers/HomeController.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?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.');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user