fix:change user side bugs
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Account;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\EditProfilePostRequest;
|
||||
use App\Models\File;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
@@ -17,8 +18,6 @@ class EditProfileController extends Controller
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function post(EditProfilePostRequest $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
@@ -32,8 +31,30 @@ class EditProfileController extends Controller
|
||||
'city_id',
|
||||
]);
|
||||
|
||||
if ($request->filled('new_password')) {
|
||||
if ($request->hasFile('image')) {
|
||||
|
||||
$image = $request->file('image');
|
||||
|
||||
$imageName = time() . rand(11111, 99999) . '.' . $image->extension();
|
||||
|
||||
$path = $image->storeAs(
|
||||
'user_images',
|
||||
$imageName,
|
||||
'public'
|
||||
);
|
||||
|
||||
$file = File::create([
|
||||
'name' => $imageName,
|
||||
'size' => $image->getSize(),
|
||||
'original_name' => $image->getClientOriginalName(),
|
||||
'path' => $path,
|
||||
'extension' => $image->extension(),
|
||||
]);
|
||||
|
||||
$inputs['image_id'] = $file->id;
|
||||
}
|
||||
|
||||
if ($request->filled('new_password')) {
|
||||
$inputs['password'] = Hash::make(
|
||||
$request->input('new_password')
|
||||
);
|
||||
@@ -46,5 +67,4 @@ class EditProfileController extends Controller
|
||||
->with('success', 'پروفایل با موفقیت بروزرسانی شد.');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,37 +8,36 @@ use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class FavoriteController extends Controller
|
||||
{
|
||||
public function toggle($type, $id)
|
||||
public function toggle(string $type, int $id)
|
||||
{
|
||||
$query = Favorite::where('user_id', Auth::id());
|
||||
$data = [
|
||||
'user_id' => auth()->id(),
|
||||
'flight_id' => null,
|
||||
'tour_id' => null,
|
||||
];
|
||||
|
||||
if ($type === 'flight') {
|
||||
$query->where('flight_id', $id);
|
||||
$data['flight_id'] = $id;
|
||||
} elseif ($type === 'tour') {
|
||||
$query->where('tour_id', $id);
|
||||
$data['tour_id'] = $id;
|
||||
} else {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$favorite = $query->first();
|
||||
$favorite = Favorite::query()
|
||||
->where('user_id', auth()->id())
|
||||
->where('flight_id', $data['flight_id'])
|
||||
->where('tour_id', $data['tour_id'])
|
||||
->first();
|
||||
|
||||
if ($favorite) {
|
||||
$favorite->delete();
|
||||
} else {
|
||||
|
||||
$data = [
|
||||
'user_id' => Auth::id(),
|
||||
];
|
||||
|
||||
if ($type === 'flight') {
|
||||
$data['flight_id'] = $id;
|
||||
} else {
|
||||
$data['tour_id'] = $id;
|
||||
}
|
||||
|
||||
Favorite::create($data);
|
||||
return back()->with('success', 'از علاقهمندیها حذف شد.');
|
||||
}
|
||||
|
||||
return back();
|
||||
Favorite::create($data);
|
||||
|
||||
return back()->with('success', 'به علاقهمندیها اضافه شد.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user