Hello I am learning Laravel. I have a picture gallery tha shows all pictures paginated but I want to only show on another page the users photos So this is the controller for the only users photos to show
public function __construct()
{
$this->middleware('auth');
}
public function show(Photos $photos)
{
$user = auth()->user();
$images = Photos::all();
if($images->user->user_id==auth()->id())
{
return view('profile',['images'=>$images,
'user'=>$user]);
}
}
//This is my photos table
public function up()
{
Schema::create('photos', function (Blueprint $table) {
$table->increments('id');
$table->unsignedinteger('user_id')->index();
$table->string('title');
$table->string('image');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('photos');
}
public function up()
{
Schema::create('photos', function (Blueprint $table) {
$table->increments('id');
$table->unsignedinteger('user_id')->index();
$table->string('title');
$table->string('image');
$table->timestamps();
});
}
'
And this is the route:
//users gallery
Route::get('/profile','ProfileController@show')->name('profile');
This is my photos model:
// protected $guarded = [];
protected $fillable = [
'user_id','title','image'
];
public function user()
{
return $this->belongsTo(User::class);
}
public function comments()
{
return $this->hasMany(Comment::class);
}
And this is my user model:
protected $fillable = [
'username','firstname','lastname','phone', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function photos()
{
return $this->hasMany(Photos::class);
}
public function comments()
{
return $this->hasMany(Comment::class);
}
public function favorite()
{
return $this->hasOne(Favorites::class);
}
The problem is that is still shows all the photos not only the user's one. Please tell me what is that I am doing wrong?