mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
Group management code.
This commit is contained in:
@@ -5,6 +5,7 @@ namespace FireflyIII\Models;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Class ObjectGroup
|
||||
@@ -31,6 +32,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class ObjectGroup extends Model
|
||||
{
|
||||
protected $fillable = ['title', 'order'];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
|
||||
*/
|
||||
@@ -38,4 +40,25 @@ class ObjectGroup extends Model
|
||||
{
|
||||
return $this->morphedByMany(PiggyBank::class, 'object_groupable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Route binder. Converts the key in the URL to the specified object (or throw 404).
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @throws NotFoundHttpException
|
||||
* @return ObjectGroup
|
||||
*/
|
||||
public static function routeBinder(string $value): ObjectGroup
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$objectGroupId = (int) $value;
|
||||
$objectGroup = self::where('object_groups.id', $objectGroupId)
|
||||
->where('object_groups.user_id', auth()->user()->id)->first();
|
||||
if (null !== $objectGroup) {
|
||||
return $objectGroup;
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user