Laravel Tutorial Image Upload Example using Intervention with Video - Part 3

In this videos i will show you how to resize image in laravel application. Generally if we are work on big project like ecommerce etc then we need to generate thumbnail image for product or user image etc. So in laravel you can do easily using intervention/image package

Video Tutorial Upload Image 


Full Resource Code 

Installing Image Intervention
composer require intervention/image

Class for intervention : config/app->'providers'
Intervention\Image\ImageServiceProvider::class

Class for intervention : config/app->'alises'
'Image' => Intervention\Image\Facades\Image::class

Add form Upload : resources/views/admin/create
{{ Form::label('image', 'Upload Image:') }}
{{ Form::file('image') }}

Add form Upload : resources/views/admin/edit
{{ Form::label('image', 'Update image :') }}
{{ Form::file('image') }}

Add column image in table Posts :

Model for Posts : app/post
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
  public $table = "posts";
  protected $fillable = [
      'title',
      'body',
      'image',
  ];
}

Change code : config/filesystems->'disks'
'local' => [
            'driver' => 'local',
            'root' => public_path('image/'),
        ],

Add class and function create for Image : app\Http\Controllers\PostsController->'store'
Class
use image

Function
if ($request->hasFile('image')) {
        $image = $request->file('image');
        $filename = time().'.'.$image->getClientOriginalExtension();
        $location = public_path('image/'.$filename);
        Image::make($image)->resize(300, 100)->save($location);
        $post->image = $filename;
      }

Add class and function update for Image : app\Http\Controllers\PostsController->'update'

Class
use Storage;

Function
if ($request->hasFile('image')) {
        $image = $request->file('image');
        $filename = time().'.'.$image->getClientOriginalExtension();
        $location = public_path('image/'.$filename);
        Image::make($image)->resize(300, 100)->save($location);

        $oldfilename = $post->image;

        $post->image = $filename;

        Storage::delete($oldfilename);
      }

Add new table cell in index : resources/views/admin/index
//table head
<th width="100px">Image</th>

//table body
<td>
<img class="img-rounded corners" width="60px" src="{{asset('image/'.$post->image)}}" alt="">
</td>

Add image to Blog Index : resources\views\blog\index
<div class="col-sm-3">
<h2><img class="img-rounded corners" width="170px" height="150px" src="{{asset('image/'.$post->image)}}" alt=""></h2>
</div>

Add image to Blog single: resources\views\blog\single
<h2><img class="img-rounded corners" width="100%" src="{{asset('image/'.$post->image)}}" alt=""></h2>

COMMENTS

Nama

BackEnd,1,Laravel Tutorial,4,Video,4,
ltr
item
Artist Code: Laravel Tutorial Image Upload Example using Intervention with Video - Part 3
Laravel Tutorial Image Upload Example using Intervention with Video - Part 3
In this videos i will show you how to resize image in laravel application. Generally if we are work on big project like ecommerce etc then we need to generate thumbnail image for product or user image etc. So in laravel you can do easily using intervention/image package
https://i.ytimg.com/vi/w1ilewiHMfA/hqdefault.jpg
https://i.ytimg.com/vi/w1ilewiHMfA/default.jpg
Artist Code
http://webartis-an.blogspot.com/2018/03/laravel-tutorial-image-upload-example.html
http://webartis-an.blogspot.com/
http://webartis-an.blogspot.com/
http://webartis-an.blogspot.com/2018/03/laravel-tutorial-image-upload-example.html
true
3425071467864085635
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy