Compare commits
No commits in common. "4090f5791a9a1d41794323c10d64341544025e43" and "f9993b4c73a15c174739a8d15f74399efb6ccb7d" have entirely different histories.
4090f5791a
...
f9993b4c73
@ -1,10 +0,0 @@
|
||||
---
|
||||
description: Git für dieses Repo immer per HTTPS (origin), kein SSH-Remote vorschlagen
|
||||
alwaysApply: true
|
||||
---
|
||||
|
||||
# Git: HTTPS für Pauker-Remote
|
||||
|
||||
- **Remote:** `origin` = `https://git.pauker.at/Stefan/Einkaufsliste.git` — Push/Pull immer über diese HTTPS-URL, Remote nicht auf SSH (`git@…`) umstellen.
|
||||
- **Agent:** Bei `git push` / `git pull` keine SSH-Alternative vorschlagen, nur HTTPS beibehalten.
|
||||
- **Auth-Fehler:** Hinweis auf Anmeldung, Personal Access Token oder Credential Manager unter HTTPS; nicht „auf SSH wechseln“ als Standard-Fix.
|
||||
@ -2,16 +2,13 @@
|
||||
|
||||
namespace App\Http\Controllers\Concerns;
|
||||
|
||||
use App\Models\ShoppingItem;
|
||||
use App\Models\ShoppingList;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
trait ResolvesCurrentShoppingList
|
||||
{
|
||||
protected function currentShoppingList(Request $request): ShoppingList
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $request->user();
|
||||
abort_if($user === null, 403);
|
||||
|
||||
@ -30,29 +27,9 @@ trait ResolvesCurrentShoppingList
|
||||
$sessionId = $request->session()->get('current_shopping_list_id');
|
||||
$current = $lists->firstWhere('id', $sessionId);
|
||||
|
||||
if ($current === null) {
|
||||
$persistedId = $user->last_active_shopping_list_id;
|
||||
$current = $lists->firstWhere('id', $persistedId);
|
||||
}
|
||||
|
||||
if ($current === null) {
|
||||
$listIds = $lists->pluck('id');
|
||||
$lastEditedListId = ShoppingItem::query()
|
||||
->whereIn('shopping_list_id', $listIds)
|
||||
->orderByDesc('updated_at')
|
||||
->orderByDesc('id')
|
||||
->value('shopping_list_id');
|
||||
$current = $lists->firstWhere('id', $lastEditedListId);
|
||||
}
|
||||
|
||||
if ($current === null) {
|
||||
$current = $lists->first();
|
||||
}
|
||||
|
||||
$request->session()->put('current_shopping_list_id', $current->id);
|
||||
|
||||
if ((int) $user->last_active_shopping_list_id !== (int) $current->id) {
|
||||
$user->forceFill(['last_active_shopping_list_id' => $current->id])->saveQuietly();
|
||||
$request->session()->put('current_shopping_list_id', $current->id);
|
||||
}
|
||||
|
||||
return $current;
|
||||
|
||||
@ -4,7 +4,6 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@ -64,9 +63,4 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
{
|
||||
return $this->belongsToMany(ShoppingList::class, 'shopping_list_user')->withTimestamps();
|
||||
}
|
||||
|
||||
public function lastActiveShoppingList(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ShoppingList::class, 'last_active_shopping_list_id');
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->foreignId('last_active_shopping_list_id')
|
||||
->nullable()
|
||||
->after('remember_token')
|
||||
->constrained('shopping_lists')
|
||||
->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropForeign(['last_active_shopping_list_id']);
|
||||
$table->dropColumn('last_active_shopping_list_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user