Sunday, May 20, 2018

Laravel 5.5 save filename to database as *.tmp - development

Laravel 5.5 save filename to database as *.tmp

I want to save my post with linked image/
My model:

class Performer extends Model
{
    protected $fillable = ['title','slug','logoimage','description','address','toplace','exp','workers','published','created_by','modified_by'];

    public function categories() {
        return $this->morphToMany('AppCategory', 'categoryable');
    }

    public function SetSlugAttribute($value)
  {
    $this->attributes['slug'] = Str::slug(mb_substr($this->title, 0, 40) . "-". CarbonCarbon::now()->format('dmyHi'), '-');
  }
}

My controller:

public function store(Request $request) {

       // dd($request);
        $performer = Performer::create($request->all());

        if ($request->input('categories')){
            $performer->categories()->attach($request->input('categories'));
        }

        if ($request->hasfile('logoimage')){
          $image = $request->file('logoimage');
          $filename = time().'.'.$image->getClientOriginalExtension();
          $location = public_path('images/uploads/logo/'.$filename);
          Image::make($image)->resize(100, 100)->save($location);
          // dd($filename); - return normal filename, 857857857.jpg as example
          $performer->logoimage= $filename;

        }


        return redirect()->route('admin.performer.index');
    }

View:

<input type="file" class="form-control" name="logoimage">

enctype=”multipart/form-data” is enabled in form.

Result:
Images saved to folder publicimagesuploadslogo normally, with *.jpg names
To database (logoimage column) saved as C:xampptmpphp915C.tmp.
WHY?
How to fix it?



from Laravel Questions and Answers https://laravelquestions.com/php/laravel-5-5-save-filename-to-database-as-tmp/
via Lzo Media

No comments:

Post a Comment