Build A Photo sharing Website with laravel 5.2 From Scratch

In This tutorial;, we will Build A photo sharing website with laravel 5.2 from scratch . Laravel is a perfect choice for amateur projects as well as enterprise solutions. There are continuous improvement & enhancements in Laravel framework by the community developers. The recent announcement of Laravel 5.2 update contains few excellent new features. It continues the improvements made in Laravel 5.1 by adding multiple authentication driver support, simplified eloquent global scopes, implicit model binding, middleware groups, opt-in authentication scaffolding, array validation improvements, rate limiting middleware, and more. First, we will create an images table. Then we’ll cover methods to resize and share images.
some important notes on larvel 5.2 before diving The tutorial

Implicit model binding

Implicit model binding is the latest feature which automatically binds a model to a route. Below is an example in code:

Recommended :  Create a commenting Application with Angular 2

php_code_7

What this does is behind the scenes call php_code_2 and inserts it into the $post variable. In Laravel 5.1, it would need to practice the Route::model method to instruct Laravel to inject the App\User instance which matches the {user} parameter in route definition. Therefore, in Laravel 5.2, the framework will automatically include this model based on the URI segment, allowing to quickly gain access to the model instances user require.

Array Validation

This is very excellent feature. For example: you have a form with an array of input fields like this:

php_code_5

While in Laravel 5.1 to add validation rules, it required looping through and adding the rules separately. Instead of having to do all that it’s been “Laravelized” into this:

php_code_6

Middleware Groups

Middleware groups enable to group many route middleware below a single, convenient key, allowing to assign several middleware to a route at once. For eg, this can be useful when building a web UI and an API within the same application. The user may group the session and CSRF routes into a web group, and possibly the rate limiter in the api group.

Recommended :  Add Fractal service provider in Laravel 5 and Lumen

Rate Limiting

A latest rate limiter middleware is presently included with the framework, facilitating to easily restrict the number of requests that a given IP address can make to a route over a particular number of minutes. For eg, to limit a route to 60 requests every minute from a single IP address, user may do the following:

php_code_4

Collections Wildcards

When utilizing a collection and wanting to pull out data, user can now pass a * as a wildcard:

php_code1

Eloquent Global Scope

In earlier versions of Laravel, global Eloquent scopes were complex and error-prone to implement; though, in Laravel 5.2, global query scopes only require to implement a single, simple method: apply.

Recommended :  A simple polymorphic relationship in laravel

Database Session Driver

The database session driver now covers user_id and ip_address so user can easily clear all sessions for a given user.

Hence, Laravel helps the application to stay alive and relevant utilizing established software development patterns.
note – please comment below if you were facing any problem or if you are new to laravel checkout this article

The following topics are covered in this tutorial:

  • Creating a database and migrating the images table
  • Creating a image model
  • Setting custom configuration values
  • Installing a third-party library
  • Creating a secure form for file upload
  • Validating and processing the form
  • Showing the image with a user interface
  • Listing images
  • Deleting the image from the database and server

so lets get started…..

prevChapter 1 of 9

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.

  • John LeVan

    I’d like to see how to implement this in a way that makes the albums tied to the user who created it.
    IE – UserA creates an album. Only he can add / remove images from it.

    • Deven Rathore

      yeah .. it is possible .. you can do this by using middlewares and laravel’s built in auth system .. or should i request author to update article ?

      • Tom V.

        Could you, please?

  • angelside

    There is no “intervention/photo” package, its “intervention/image” and all “photo” words is wrong, its “image”.

    Image::make() …

Pin It on Pinterest

Shares