mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 03:43:07 +00:00
Fix #4656
This commit is contained in:
@@ -22,7 +22,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Eloquent;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
@@ -33,13 +32,13 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
/**
|
||||
* FireflyIII\Models\Preference
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $id
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property int $user_id
|
||||
* @property string $name
|
||||
* @property int|string|array|null $data
|
||||
* @property-read User $user
|
||||
* @property int $user_id
|
||||
* @property string $name
|
||||
* @property int|string|array|null $data
|
||||
* @property-read User $user
|
||||
* @method static Builder|Preference newModelQuery()
|
||||
* @method static Builder|Preference newQuery()
|
||||
* @method static Builder|Preference query()
|
||||
@@ -73,19 +72,29 @@ class Preference extends Model
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
* @return Preference
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public static function routeBinder(string $value): Preference
|
||||
{
|
||||
if (auth()->check()) {
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
/** @var Preference $preference */
|
||||
/** @var Preference|null $preference */
|
||||
$preference = $user->preferences()->where('name', $value)->first();
|
||||
if (null !== $preference) {
|
||||
return $preference;
|
||||
}
|
||||
$default = config('firefly.default_preferences');
|
||||
if (array_key_exists($value, $default)) {
|
||||
$preference = new Preference;
|
||||
$preference->name = $value;
|
||||
$preference->data = $default[$value];
|
||||
$preference->user_id = $user->id;
|
||||
$preference->save();
|
||||
|
||||
return $preference;
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
|
Reference in New Issue
Block a user