Today, We want to share with you How to upload Profile Images to Users using Laravel 6?.In this post we will show you Upload profile picture using Laravel 6, hear for Live Image Upload using jQuery, PHP Laravel 6 and MySQL we will give you demo and example for implement.In this post, we will learn about Image preview and upload using PHP Laravel 6 and MySQL database with an example.
How to upload Profile Images to Users using Laravel 6?
There are the Following The simple About Upload Profile Picture in Laravel 6 Registration Full Information With Example and source code.
As I will cover this Post with live Working example to develop Laravel Avatar Image Upload Tutorial With Example, so the Upload user profile image and save to data base – PHP Laravel 6 MYSQLI is used for this example is following below.
How to upload profile picture Avatar in Laravel?
Open create_users_table.php
$table->string('profiledp')->default('member.jpg'); public function up() { Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('email')->unique(); $table->string('password'); $table->string('profiledp')->default('member.jpg'); $table->rememberToken(); $table->timestamps(); }); }
Setup User Profile Page
resources > views > layouts > app.blade.php
Handle Profile Picture Upload Request
routes > web.php
Route::get('myaccount', 'ProfileController@myaccount'); Route::post('myaccount', 'ProfileController@update_profiledp');
ProfileController.php
public function myaccount() { $user = Auth::user(); return view('myaccount',compact('user',$user)); } public function update_profiledp(Request $request){ $request->validate([ 'profiledp' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', ]); $user = Auth::user(); $profiledpName = $user->id.'_profiledp'.time().'.'.request()->profiledp->getClientOriginalExtension(); $request->profiledp->storeAs('profiledps',$profiledpName); $user->profiledp = $profiledpName; $user->save(); return back() ->with('success','You have successfully upload image.'); }
resources > views > myaccount.blade.php
@extends('layouts.app') @section('content')@endsection@if ($message = Session::get('success')){{ $message }}@endif @if (count($errors) > 0)Whoops! There were some problems with your input.@endif
@foreach ($errors->all() as $error)
- {{ $error }}
@endforeach
{{$user->name}}
Web Programming Tutorials Example with Demo
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Laravel Avatar Image Upload Tutorial With Example.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.