PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 1, 2022

[FIXED] Laravel 5 - Image Upload and Resize using Intervention Image Package

 February 01, 2022     laravel, laravel-5, model-view-controller     No comments   

Issue

I want to upload a photo with some posts.

This is my controller

public function store(WisataRequest $request)
{
  $input = $request->all();

  if ($request->hasFile('gambar')) {
    $gambar = $request->file('gambar');
    $filename = time() . '.' . $gambar->getClientOriginalExtension();

    if ($request->file('gambar')->isValid()) {
      Image::make($gambar)->resize(300, 300)->save(public_path('/upload/gambar/'.$filename));
      $input->gambar = $filename;
      $input->save();
    }
  }

  $wisata = Wisata::create($input);
  Session::flash('flash_message', 'Berhasil Terkirim');
  return redirect('admin_wisata');
}

But when it runs i found an error Attempt to assign property of non-object


Solution

Change

$input->gambar = $filename;
$input->save();

To

$input['gambar']= $filename;


Answered By - Vu Hoang Duc
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing