each user can see his own comments ??

Ilias Bekkali posted 10 months ago

Hello evebody :i have a question in laravel , i m a beginner ,
so i did the following pro-gramme with a database including 3 tables , the first one is the normal users table , the second one todos table , that has the following arguments : ``` $table->increments('id'); $table->text('body'); $table->timestamps();

                                                                                                                                         the text 'body' , that i specified in the table todos is the one ,that takes the comments . in order to show for each user his own comments , i mean his own table todos , i create a third table , user_todo, that contains the following components :          ```
```                                                                                                                                      it means the one that makes the connections with the 2 other tables , using the ids of each table in the third one .                                                              then i created  3 models todo.php ,user.php , user_todo.php ,in user.php i wrote the following code :                                                  ```

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
    use Notifiable;

     * The attributes that are mass assignable.
     * @var array
    protected $fillable = [
        'name', 'email', 'password',

     * The attributes that should be hidden for arrays.
     * @var array
    protected $hidden = [
        'password', 'remember_token',
    public function mobiles(){
      return $this->hasMany('App\todo');
    public function todo_User(){
    return   $this->hasOne('App\todo_User');

in todo.php , i wrote this code : ```

<?php namespace App; use Illuminate\Database\Eloquent\Model; class todo extends Model { public function Users(){ return $this->belongsTo('App\User'); } } ``` then finally in user_todo.php , i wrote this code: ``` <?php namespace App; use Illuminate\Database\Eloquent\Model; class todo_User extends Model { public function User(){ return $this->belongsTo('App\User'); } } ``` what should i add to show the comments that belongs to each user in his own login area , because i watch the comments of the all users in each user page .

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us