Bonjour,
J'aimerais faire un système de date d'échéance sous Laravel mais je n'y arrive pas voici mon code.
Table
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('firstname');
$table->string('email')->unique();
$table->date('birthday');
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
ProfilController
<?php
namespace App\Http\Controllers;
use App\Http\Controllers;
use App\User;
use Carbon\Carbon;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class ProfilController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
$this->middleware('owner', ['only' => ['edit', 'update', 'getEditResource']]);
}
public function index($name, $firstname, $id)
{
$authinfo = Auth::user();
$userinfo = User::where('name', $name)->where('firstname', $firstname)->where('id', $id)->firstorfail();
if($authinfo->created_at >= date("Y-m-d H:i:s", strtotime("$authinfo->created_at +1 days"))){
dd("Tu doit t'abonner");
}else{
dd("Tu est premium");
}
//return view('users.particulier.profil', compact('authinfo', 'userinfo'));
}
public function getEditResource($name, $firstname, $id)
{
return User::where('name', $name)->where('firstname', $firstname)->where('id', $id)->firstorfail();
}
public function edit()
{
$authinfo = Auth::user();
return view('users.particulier.edit', compact('authinfo'));
}
public function update(Request $request)
{
$user = Auth::user();
$this->validate($request, [
'name' => 'required',
'firstname' => 'required',
'avatar' => "image"
]);
$user->update($request->only('name', 'firstname'));
$user->profil->update($request->only('job', 'about', 'avatar'));
return redirect(route('profil', [strtolower(Auth::user()->name), strtolower(Auth::user()->firstname), Auth::id()]))->with('success', 'Votre profil à bien était modifié');
}
}
Mon utilisateur sont create_at = 2017-11-13 20:57:06
Mon problème c'est que la date d'échéance ne marche pas !
Merci.