table deleting
This commit is contained in:
@@ -43,6 +43,22 @@ class TableController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete(Request $request, User $user, string $table)
|
||||
{
|
||||
/** @var Table $tableModel */
|
||||
$tableModel = $user->tables()->where('name', $table)->first();
|
||||
if ($tableModel === null) abort(404, "No such table.");
|
||||
$this->authorize('delete', $tableModel);
|
||||
|
||||
if ($request->get('table-name', null) !== $table) {
|
||||
return $this->backWithErrors(['table-name' => 'Fill table name']);
|
||||
}
|
||||
|
||||
$tableModel->delete();
|
||||
|
||||
return redirect(route('profile.view', $user->name));
|
||||
}
|
||||
|
||||
/**
|
||||
* SHow a form for creating a new table
|
||||
*
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ class Kernel extends HttpKernel
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
'throttle:60,15', // try to prevent people refresh-spamming the server to game table visit counts
|
||||
'throttle:120,15', // try to prevent people refresh-spamming the server to game table visit counts
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
|
||||
@@ -14,7 +14,8 @@ trait Reportable
|
||||
{
|
||||
public static function bootReportable()
|
||||
{
|
||||
static::deleting(function(Reportable $self) {
|
||||
static::deleting(function($self) {
|
||||
/** @var Reportable $self */
|
||||
$self->reportsOf()->delete();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -131,6 +131,10 @@ class Table extends BaseModel
|
||||
return route('table.conf', ['user' => $this->cachedOwner()->name, 'table' => $this->name]);
|
||||
}
|
||||
|
||||
if ($name == 'deleteRoute') {
|
||||
return route('table.delete', ['user' => $this->cachedOwner()->name, 'table' => $this->name]);
|
||||
}
|
||||
|
||||
return parent::__get($name);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,11 @@ class WidgetFactory
|
||||
|
||||
public function par($text, $extraClasses='', $escape=true)
|
||||
{
|
||||
if (false === strpos($extraClasses, 'mb-')) $extraClasses .= ' mb-2';
|
||||
|
||||
return
|
||||
"<div class=\"row\">".
|
||||
"<p class=\"col-md-$this->fieldCols offset-md-$this->labelCols mb-2 ".e($extraClasses)."\">".
|
||||
"<p class=\"col-md-$this->fieldCols offset-md-$this->labelCols ".e($extraClasses)."\">".
|
||||
($escape ? e($text) : $text) .
|
||||
"</p>".
|
||||
"</div>";
|
||||
|
||||
Reference in New Issue
Block a user