Archived
1
0
Fork 0

Formatting fixes.

This commit is contained in:
Henrik Hautakoski 2023-02-19 13:56:09 +01:00
parent 0437947c82
commit 86b9f3d2f0
7 changed files with 161 additions and 161 deletions

View file

@ -29,25 +29,25 @@ class AccountForm extends Component
'password' => 'new password',
];
public function mount(Request $request)
{
public function mount(Request $request)
{
$this->record = $request->user();
$this->username = $this->record->username;
}
}
/**
* Validation rules
*/
protected function rules()
{
return [
'password_current' => [ 'required', 'password' ],
'password' => [ Password::min(8)->letters()->mixedCase()->numbers(), 'confirmed' ]
];
}
/**
* Validation rules
*/
protected function rules()
{
return [
'password_current' => ['required', 'password'],
'password' => [Password::min(8)->letters()->mixedCase()->numbers(), 'confirmed']
];
}
public function updated($property, $value)
public function updated($property, $value)
{
if ($property == 'password_confirmation') {
$property = 'password';
@ -64,12 +64,12 @@ class AccountForm extends Component
$this->record->save();
return redirect()->route('admin')
->with('info', __('Password was successfully updated.'));
->with('info', __('Password was successfully updated.'));
}
public function render()
{
return view('form.account')
->layout('layouts.admin');
->layout('layouts.admin');
}
}

View file

@ -9,62 +9,62 @@ use App\Models\Wow;
class CardForm extends ModelForm
{
/**
* Array of available characters
*/
public $characters;
/**
* Array of available characters
*/
public $characters;
/**
* Array of available raids
*/
public $raids;
/**
* Array of available raids
*/
public $raids;
/**
* Redirect after this route after record was created.
*/
public string $redirect_route = 'admin.card.index';
/**
* Redirect after this route after record was created.
*/
public string $redirect_route = 'admin.card.index';
public function mount(Card $card)
{
$this->record = $card;
$this->characters = Character::all()->pluck('name', 'id');
$this->raids = Raid::all()->pluck('name', 'id');
$this->classes = Wow::$classes;
$this->exist = $card->exists;
}
/**
* Validation rules
*/
protected function rules()
{
return [
'record.body' => 'required|string|min:3|max:200',
'record.character_id' => 'exists:' . Character::class . ',id|nullable',
'record.raid_id' => 'exists:' . Raid::class . ',id|nullable',
'record.class' => 'in:' . collect($this->classes)->keys() . '|nullable',
];
}
public function updated($property, $value)
public function mount(Card $card)
{
// Hack to force empty value to null.
if (in_array($property, ['record.character_id', 'record.raid_id', 'record.class'])) {
if (empty($value)) {
$this->{$property} = null;
}
}
$this->record = $card;
$this->characters = Character::all()->pluck('name', 'id');
$this->raids = Raid::all()->pluck('name', 'id');
$this->classes = Wow::$classes;
$this->exist = $card->exists;
}
/**
* Validation rules
*/
protected function rules()
{
return [
'record.body' => 'required|string|min:3|max:200',
'record.character_id' => 'exists:' . Character::class . ',id|nullable',
'record.raid_id' => 'exists:' . Raid::class . ',id|nullable',
'record.class' => 'in:' . collect($this->classes)->keys() . '|nullable',
];
}
public function updated($property, $value)
{
// Hack to force empty value to null.
if (in_array($property, ['record.character_id', 'record.raid_id', 'record.class'])) {
if (empty($value)) {
$this->{$property} = null;
}
}
$this->validateOnly($property);
}
public function getSubjectProperty()
{
if ($this->record->character_id) {
return $this->characters[$this->record->character_id];
} else if ($this->record->class) {
return $this->classes[$this->record->class];
}
return "Somebody";
}
public function getSubjectProperty()
{
if ($this->record->character_id) {
return $this->characters[$this->record->character_id];
} else if ($this->record->class) {
return $this->classes[$this->record->class];
}
return "Somebody";
}
}

View file

@ -6,24 +6,24 @@ use App\Models\Character;
class CharacterForm extends ModelForm
{
/**
* Redirect after this route after record was created.
*/
public string $redirect_route = 'admin.character.index';
/**
* Redirect after this route after record was created.
*/
public string $redirect_route = 'admin.character.index';
public function mount(Character $character)
{
$this->record = $character;
$this->exist = $character->exists;
}
public function mount(Character $character)
{
$this->record = $character;
$this->exist = $character->exists;
}
/**
* Validation rules
*/
protected function rules()
{
return [
'record.name' => 'required|string|min:3|max:14',
];
}
/**
* Validation rules
*/
protected function rules()
{
return [
'record.name' => 'required|string|min:3|max:14',
];
}
}

View file

@ -7,31 +7,31 @@ use Illuminate\Support\Facades\Auth;
class LoginForm extends Component
{
public $username;
public $username;
public $password;
public $password;
protected $rules = [
protected $rules = [
'username' => 'required|string|min:3',
'password' => 'required|string',
];
public function submit()
{
$this->validate();
public function submit()
{
$this->validate();
$cred = [
'username' => $this->username,
'password' => $this->password
];
$cred = [
'username' => $this->username,
'password' => $this->password
];
if (!Auth::attempt($cred)) {
session()->flash('message', __('auth.failed'));
return;
if (!Auth::attempt($cred)) {
session()->flash('message', __('auth.failed'));
return;
}
return redirect()->intended('/admin');
}
return redirect()->intended('/admin');
}
/**
* Render the setup page

View file

@ -9,68 +9,68 @@ use Illuminate\Support\Str;
abstract class ModelForm extends Component
{
use Alert;
use Alert;
/**
* The model record
*/
public $record;
/**
* The model record
*/
public $record;
/**
* True if the record already exists in the database.
*/
public bool $exist;
/**
* True if the record already exists in the database.
*/
public bool $exist;
/**
* Redirect after this route after record was created.
*/
public string $redirect_route;
/**
* Redirect after this route after record was created.
*/
public string $redirect_route;
/**
* Get the name of the model
*/
public function getModelName() : string
{
return Str::afterLast(get_class($this->record), '\\');
}
/**
* Get the name of the model
*/
public function getModelName(): string
{
return Str::afterLast(get_class($this->record), '\\');
}
public function updated($property, $value)
public function updated($property, $value)
{
$this->validateOnly($property);
}
/**
* Returns true if this record has not been stored in the database.
*/
public function isNew() : bool
{
return !$this->exist;
}
/**
* Returns true if this record has not been stored in the database.
*/
public function isNew(): bool
{
return !$this->exist;
}
/**
* Submit the form, create/update record.
*/
public function submit()
{
$this->validate();
$this->record->save();
/**
* Submit the form, create/update record.
*/
public function submit()
{
$this->validate();
$this->record->save();
if ($this->isNew()) {
return redirect()->route($this->redirect_route)
->with('info', __("{$this->getModelName()} was successfully created."));
}
if ($this->isNew()) {
return redirect()->route($this->redirect_route)
->with('info', __("{$this->getModelName()} was successfully created."));
}
$this->info(__("{$this->getModelName()} was successfully updated."));
}
$this->info(__("{$this->getModelName()} was successfully updated."));
}
/**
* Render the setup page
*/
public function render()
{
$script = Str::lower($this->getModelName());
$script = Str::lower($this->getModelName());
return view("form.$script")
->layout('layouts.admin');
->layout('layouts.admin');
}
}

View file

@ -6,24 +6,24 @@ use App\Models\Raid;
class RaidForm extends ModelForm
{
/**
* Redirect after this route after record was created.
*/
public string $redirect_route = 'admin.raid.index';
/**
* Redirect after this route after record was created.
*/
public string $redirect_route = 'admin.raid.index';
public function mount(Raid $raid)
{
$this->record = $raid;
$this->exist = $raid->exists;
}
public function mount(Raid $raid)
{
$this->record = $raid;
$this->exist = $raid->exists;
}
/**
* Validation rules
*/
protected function rules()
{
return [
'record.name' => 'required|string|min:2|max:20',
];
}
/**
* Validation rules
*/
protected function rules()
{
return [
'record.name' => 'required|string|min:2|max:20',
];
}
}

View file

@ -11,7 +11,7 @@ abstract class GameComponent extends Component
/**
* Get the game service object
*/
public function getServiceProperty() : GameService
public function getServiceProperty(): GameService
{
return app()->make(GameService::class);
}