Merge remote-tracking branch 'origin/dev' into features/notifications
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
class ProfilePhotoController extends Controller
|
||||||
|
{
|
||||||
|
public function show(Request $request)
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
return response()->json(['profile_photo_path' => $user->profile_photo_path]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $request)
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'photo' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user = $request->user();
|
||||||
|
$path = $request->file('photo')->store('profile-photos', 'public');
|
||||||
|
|
||||||
|
// Supprimer l'ancienne photo si elle existe
|
||||||
|
if ($user->profile_photo_path) {
|
||||||
|
Storage::disk('public')->delete($user->profile_photo_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->update(['profile_photo_path' => $path]);
|
||||||
|
|
||||||
|
return response()->json(['profile_photo_path' => $path]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(Request $request)
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
if ($user->profile_photo_path) {
|
||||||
|
Storage::disk('public')->delete($user->profile_photo_path);
|
||||||
|
$user->update(['profile_photo_path' => null]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json(['message' => 'Photo supprimée']);
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-1
@@ -25,7 +25,8 @@ class User extends Authenticatable
|
|||||||
'phone',
|
'phone',
|
||||||
'validate',
|
'validate',
|
||||||
'role',
|
'role',
|
||||||
'verified_at'
|
'verified_at',
|
||||||
|
'profile_photo_path'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ class UserService
|
|||||||
"updated_at" => $user->updated_at,
|
"updated_at" => $user->updated_at,
|
||||||
"verfied_at" => $user->verfied_at,
|
"verfied_at" => $user->verfied_at,
|
||||||
"validate" => $user->validate,
|
"validate" => $user->validate,
|
||||||
"tasks" => $user->tasks
|
"tasks" => $user->tasks,
|
||||||
|
"profile_photo_path" => $user->profile_photo_path,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->string('profile_photo_path', 2048)->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('profile_photo_path');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -3,6 +3,14 @@
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\ExportController;
|
use App\Http\Controllers\ExportController;
|
||||||
|
use App\Http\Controllers\ProfilePhotoController;
|
||||||
|
|
||||||
|
Route::middleware('auth:sanctum')->group(function () {
|
||||||
|
Route::post('/profile-photo', [ProfilePhotoController::class, 'update']);
|
||||||
|
Route::delete('/profile-photo', [ProfilePhotoController::class, 'destroy']);
|
||||||
|
Route::get('/profile-photo', [ProfilePhotoController::class, 'show']);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
Route::get('/export/ics/{userId}', [ExportController::class, 'exportIcs']);
|
Route::get('/export/ics/{userId}', [ExportController::class, 'exportIcs']);
|
||||||
Route::get("/hello", function (Request $request) {
|
Route::get("/hello", function (Request $request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user