Permalink
Browse files

Episode 65

  • Loading branch information...
JeffreyWay committed Aug 10, 2017
1 parent 261a84b commit 4e3f09669477102f396c809137cb8aa1b64e0232
@@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
class UserAvatarController extends Controller
{
public function store()
{
$this->validate(request(), [
'avatar' => ['required', 'image']
]);
auth()->user()->update([
'avatar_path' => request()->file('avatar')->store('avatars', 'public')
]);
return response([], 204);
}
}
@@ -0,0 +1,23 @@
<?php
namespace App\Policies;
use App\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class UserPolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can update the given profile.
*
* @param \App\User $signedInUser
* @param \App\User $user
* @return boolean
*/
public function update(User $signedInUser, User $user)
{
return $signedInUser->id === $user->id;
}
}
@@ -3,7 +3,6 @@
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
@@ -15,6 +14,7 @@ class AuthServiceProvider extends ServiceProvider
protected $policies = [
'App\Thread' => 'App\Policies\ThreadPolicy',
'App\Reply' => 'App\Policies\ReplyPolicy',
'App\User' => 'App\Policies\UserPolicy',
];
/**
@@ -16,7 +16,7 @@ class User extends Authenticatable
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'name', 'email', 'password', 'avatar_path'
];
/**
@@ -81,6 +81,17 @@ public function read($thread)
);
}
/**
* Get the path to the user's avatar.
*
* @param string $avatar
* @return string
*/
public function getAvatarPathAttribute($avatar)
{
return asset($avatar ?: 'images/avatars/default.png');
}
/**
* Get the cache key for when a user reads a thread.
*
@@ -18,6 +18,7 @@ public function up()
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->string('avatar_path')->nullable();
$table->rememberToken();
$table->timestamps();
});
Binary file not shown.
Oops, something went wrong.

0 comments on commit 4e3f096

Please sign in to comment.