Add avatar field to users table and allow images to be uploaded using settings page
MODIFY
app/Http/Controllers/SettingsController.php
app/Http/Controllers/SettingsController.php
@@ -19,8 +19,16 @@ class SettingsController extends Controller {
}
public function store(Request $request) {
+ // TODO VALIDATE
+
$user = Auth::user();
+ if ($request->hasFile('avatar')) {
+ $request->file('avatar')->store('public/avatars');
+
+ $user->avatar = $request->file('avatar')->hashName();
+ }
+
$user->name = $request->input('name');
$user->email = $request->input('email');
$user->language = $request->input('language');

MODIFY
database/migrations/2014_10_12_000000_create_users_table.php
database/migrations/2014_10_12_000000_create_users_table.php
@@ -9,6 +9,7 @@ class CreateUsersTable extends Migration {
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->integer('currency_id')->unsigned();
+ $table->string('avatar')->nullable();
$table->string('name');
$table->string('email')->unique();
$table->string('password');

MODIFY
resources/views/settings.blade.php
resources/views/settings.blade.php
<div class="spacing-bottom-large color-dark">Account</div>
<div class="box">
<div class="section">
- <form method="POST">
+ <form method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
+ <div class="input input--small">
+ <label>Avatar</label>
+ @if (Auth::user()->avatar)
+ <img src="/storage/avatars/{{ Auth::user()->avatar }}" style="width: 200px; height: 200px; border-radius: 5px; object-fit: cover;" />
+ @else
+ <div>You don't have an avatar</div>
+ @endif
+ <input type="file" name="avatar" />
+ </div>
<div class="input input--small">
<label>Name</label>
<input type="text" name="name" value="{{ Auth::user()->name }}" />

Add avatar field to users table and allow images to be uploaded using settings page