Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

Guest Posting Sites
  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
  • Advertise
  • About
  • Contact Us

How to upload Profile Images to Users using Laravel 6?

March 17, 2020 Pakainfo Technology, Ajax, JavaScript, jQuery, Laravel, Mysql, Mysqli, php, Programming Leave a comment

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?

Contents

  • How to upload Profile Images to Users using Laravel 6?
    • How to upload profile picture Avatar in Laravel?
    • Setup User Profile Page
    • Handle Profile Picture Upload Request
    • Read
    • Summary
    • Related posts

There are the Following The simple About Upload Profile Picture in Laravel 6 Registration Full Information With Example and source code.

Also Read This 👉   Laravel File Upload Validation Rules Example

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

<div class="dropdown-menu" aria-labelledby="navbarDropdown">
    <a class="dropdown-item" href="/myaccount">
        User Profile
    </a>
    <a class="dropdown-item" href="{{ route('logout') }}"
       onclick="event.preventDefault();
                     document.getElementById('logout-form').submit();">
        {{ __('Logout') }}
    </a>

    <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
        @csrf
    </form>
</div>

Handle Profile Picture Upload Request

routes > web.php

Route::get('myaccount', '[email protected]');
Route::post('myaccount', '[email protected]_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')
    <div class="container">
        <div class="row">
            @if ($message = Session::get('success'))

                <div class="alert alert-success alert-block">

                    <button type="button" class="close" data-dismiss="alert">×</button>

                    <strong>{{ $message }}</strong>

                </div>

            @endif

            @if (count($errors) > 0)
                <div class="alert alert-danger">
                    <strong>Whoops!</strong> There were some problems with your input.<br><br>
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif
        </div>
        <div class="row justify-content-center">

            <div class="myaccount-header-container">
                <div class="myaccount-header-img">
                    <img class="rounded-circle" src="/storage/profiledps/{{ $user->profiledp }}" />
                    <!-- badge -->
                    <div class="rank-label-container">
                        <span class="label label-default rank-label">{{$user->name}}</span>
                    </div>
                </div>
            </div>

        </div>
        <div class="row justify-content-center">
            <form action="/myaccount" method="post" enctype="multipart/form-data">
                @csrf
                <div class="form-group">
                    <input type="file" class="form-control-file" name="profiledp" id="profiledpFile" aria-describedby="fileHelp">
                    <small id="fileHelp" class="form-text text-muted">Please upload a valid image file. Size of image should not be more than 2MB.</small>
                </div>
                <button type="submit" class="btn btn-primary">Submit</button>
            </form>
        </div>
    </div>
@endsection

Web Programming Tutorials Example with Demo

Read :

  • Jobs
  • Make Money
  • Programming
Also Read This 👉   Laravel Image Upload Validation Tutorial

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.

Related posts:

  1. How to Upload Images on Server in PHP?
  2. PHP Multiple images upload using jQuery Ajax
  3. Image Upload in Laravel 7 Example Tutorial
  4. validation Update User Profile in Laravel 5.7
  5. Laravel 5.8 Multiple Images Upload
  6. Laravel 6.2 Dropzone Multiple Image Upload Tutorial
Also Read This 👉   Laravel 500 internal server error
how to upload image in registration form in laravelImage preview and upload using PHP Laravel 6 and MySQL databaselaravel api upload imageLaravel Avatar Image Upload Tutorial With Examplelaravel image uploadlaravel image upload packagelaravel image upload tutoriallaravel upload image to databaselaravel upload image to storageLaravel User ImageLive Image Upload using jQueryPHP Laravel 6 And MySQLupdate profile picture in laravelUpload Profile Picture in Laravel 6 RegistrationUpload profile picture using Laravel 6Upload user profile image and save to data base - PHP Laravel 6 MYSQLI

Post navigation

Previous Post:Laravel 6 Eloquent Joins Queries Example Tutorial
Next Post:Coronavirus Basic information | treatment | news | Health

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here
Guest Posting Sites

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (64) Ajax (464) AngularJS (377) ASP.NET (61) Bio (109) Bollywood (108) Codeigniter (175) CSS (98) Earn Money (69) Education (61) Entertainment (130) fullform (86) Google Adsense (63) Highcharts (77) History (40) Hollywood (109) JavaScript (1357) Jobs (42) jQuery (1423) Laravel (1088) LifeStyle (53) movierulz4 (63) Mysql (1029) Mysqli (890) php (2121) Programming (2332) Python (97) Software (166) Software (88) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (141) Technology (2392) Tips and Tricks (119) Tools (203) Top10 (477) Trading (89) Trending (71) VueJs (250) Web Technology (104) webtools (191) wordpress (166) World (322)

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Info Grepper
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

© 2023 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype Guest Posting Sites