Group management code.

This commit is contained in:
James Cole
2020-06-20 10:10:55 +02:00
parent b54ef9f5e5
commit 5b29e78c4b
25 changed files with 737 additions and 14 deletions

View File

@@ -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;
}
}