ok i change my class.
But on my controller i add what ?
and i dont understand that : $evenements = $user->comments;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi
i have 3 table :
the table user :
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('firstname');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('categorie_user');
$table->string('droit');
$table->string('phone');
$table->string('blocked');
$table->date('date_evenement');
$table->rememberToken();
$table->timestamps();
});
}
the table evenement :
public function up()
{
Schema::create('evenements', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('categorie_id');
$table->string('categorie_user');
$table->string('name');
$table->string('description');
$table->string('ville');
$table->string('rue');
$table->date('date_evenement');
$table->string('heure');
$table->mediumText('image')->nullable();
$table->timestamps();
});
}
and the table participant:
public function up()
{
Schema::create('participants', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('user_id');
$table->integer('evenement_id');
$table->timestamps();
});
}
When a user subscribe at an event i save his id and the id of event of my table participant.
But after i want display the event whitch the user as subscribe. So i need to use belong to many. So i add this :
class User extends Authenticatable
{
public function evenements()
{
return $this->belongsToMany('App\Evenement');
}
}
and this :
class Evenement extends Model
{
public function users()
{
return $this->belongsToMany('App\Users');
}
}
but how display the event information ??
Ty
public function index()
{
$user = User::with('evenements')->find(auth()->user()->id);
return view('user.eventuser.index',compact('user'));
}
At Blade
@foreach($user->evenements as $evenement)
<h1>{{ evenement->name }}</h1>
<p>{{ evenement->description }}</p>
@endforeach
Please or to participate in this conversation.