create a photo gallery with laravel

In this tutorial we’ll code a simple photo gallery system with Laravel. We’ll also cover Laravel’s built-in file validation, file upload, and the hasMany database relation mechanism. We will use thevalidation class to validate the data and files. Also, we’ll cover the file class for processing files. The following topics are covered in this chapter:

  • Creating an Album model
  • Creating an Image model
  • Creating an album
  • Creating a photo upload form
  • Moving photos between albums

Lets Get started…

note – if you are newbie to laravel and wanna know what laravel is… you can refer these article or official documentation of laravel

About the author

Deven Rathore

I'm Deven Rathore, a multidisciplinary & self-taught designer with 3 years of experience. I'm passionate about technology, music, coffee, traveling and everything visually stimulating. Constantly learning and experiencing new things.

  • Christopher

    the syntax highlighting is not showing correctly

    • Deven Rathore

      sorry for late reply ! can you please tell me where is not showing correctly ?

      • lino

        may be this ” & gt; ” it showing instead of ” > “

        • Deven Rathore

          ok thanks i will fix it

        • Deven Rathore

          thanks i have fixed that ! i am now just using pre tag simple solution 🙂

  • unbiased observer

    I have gone with the creation of this project one line at a time, I chose to name the model (Image) rather than (Photos) to be consistent, and I get this error

    BadMethodCallException in Builder.php line 1999:
    Call to undefined method IlluminateDatabaseQueryBuilder::Image()
    when I try to track it, it ends in this line:

    $albums = Album::with(‘Photos’)->get();
    return View::make(‘index’)
    I tried to name it with(appImage) but no luck, can you help me out please?

    by the way, you’re doing an excellent job there, thanks so much.

  • Thomas Pfuhl

    Hello, thanks for this fine tutorial. However, it seems not to fit to the Laravel 5.1 directory structure. Is there an update ?

    • Deven Rathore

      i will upadate it as soon as possible ! now busy in projects 🙁

  • Ashok raj

    Command will generate a migration file underapp/database/migrations CMD:php artisan make:migration create_albums_table –create=albums –table

    • Deven Rathore

      sorry but what’s your point here ?

      • Ashok raj

        Over all its the good tutorial for beginners… I think you have to double check your commands before posting…Thats the point …

        • ok thanks ! will be doing from next time !

        • Fatih Akgun

          agree it does not say how to create a migration, beginners won’t understand how to create a migration

  • thanks for the album gallery laravel project. I think there is Albums Object missing in :
    and view: album.blade.php where you foreach through the object albums as others.
    you are not providing the obj. albums in Albumscontroller::getAlbum($id).

    • let me see that btw ! thanks 4 pointing it out

    • medraouf moussa

      How did you solve that ?

      • Sergio Peluzzi

        public function getAlbum($id)


        $data[‘album’] = $this->album->with(‘Photos’)->find($id);

        $data[‘albums’] = $this->album->all();

        return view(‘album’)->with($data);


        Obs. I’m using depency injection on __construct(). if u dont replace $this->album to Album::

  • Fatih Akgun

    open up your terminal, navigate through your project folder, and run the following command: “where is the command ?”

    you are missing this command “php artisan make:migration create_albums_table”

  • application fire
    • Nathan Scherneck

      The code is included in the tutorial.

  • application fire

    I have this error when I want to create an album
    TokenMismatchException in VerifyCsrfToken.php line 67:

    • Nathan Scherneck

      Add this to your form..

  • Beaneh

    Great tutorial. Have you uploaded the code anywhere?

    • Nathan Scherneck

      So many derelict Laravel tutorials out there.

  • Tomasz Czerwinski

    It would be faster just to make a pivot table from albums and photos.
    Second thing, if you are talking about albums and photos in plural, than update this tutorial to show people how to upload multiple images, not just one.
    And third thing… we have Laravel 5.3 now 😉

  • Костя Белоус

    i have an error
    ErrorException in d17e4d0327979a8a446079b4be560aa37d15c74a.php line 66:
    Undefined variable: albums (View: album.blade.php)

  • Albert Mungochi II

    Please Help. Class ‘BaseController’ not found

  • Carlos Hernández

    Thank you very much!

    • Carlos Hernández

      I could adapt it to laravel 5.4 without problems

Pin It on Pinterest