Custom user fields during registration and profile edit #711
This commit is contained in:
@@ -9,14 +9,14 @@ use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @property string $name
|
||||
* @property string $description
|
||||
* @property string $disk
|
||||
* @property string $path
|
||||
* @property bool $public
|
||||
* @property int $download_count
|
||||
* @property string $url
|
||||
* @property string $filename
|
||||
* @property string $name
|
||||
* @property string $description
|
||||
* @property string $disk
|
||||
* @property string $path
|
||||
* @property bool $public
|
||||
* @property int $download_count
|
||||
* @property string $url
|
||||
* @property string $filename
|
||||
*/
|
||||
class File extends Model
|
||||
{
|
||||
|
||||
@@ -14,11 +14,11 @@ use Carbon\Carbon;
|
||||
* Holds various journals, depending on the morphed_type and morphed_id columns
|
||||
*
|
||||
* @property mixed id
|
||||
* @property Money $balance
|
||||
* @property string $currency
|
||||
* @property Carbon $updated_at
|
||||
* @property Carbon $post_date
|
||||
* @property Carbon $created_at
|
||||
* @property Money $balance
|
||||
* @property string $currency
|
||||
* @property Carbon $updated_at
|
||||
* @property Carbon $post_date
|
||||
* @property Carbon $created_at
|
||||
* @property \App\Models\Enums\JournalType type
|
||||
* @property mixed morphed_type
|
||||
* @property mixed morphed_id
|
||||
|
||||
@@ -13,11 +13,11 @@ use Carbon\Carbon;
|
||||
/**
|
||||
* Class Ledger
|
||||
*
|
||||
* @property Money $balance
|
||||
* @property string $currency
|
||||
* @property Carbon $updated_at
|
||||
* @property Carbon $post_date
|
||||
* @property Carbon $created_at
|
||||
* @property Money $balance
|
||||
* @property string $currency
|
||||
* @property Carbon $updated_at
|
||||
* @property Carbon $post_date
|
||||
* @property Carbon $created_at
|
||||
*/
|
||||
class Ledger extends Model
|
||||
{
|
||||
|
||||
@@ -6,10 +6,10 @@ use App\Contracts\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* @property string $id The Simbrief OFP ID
|
||||
* @property int $user_id The user that generated this
|
||||
* @property string $flight_id Optional, if attached to a flight, removed if attached to PIREP
|
||||
* @property string $pirep_id Optional, if attached to a PIREP, removed if attached to flight
|
||||
* @property string $id The Simbrief OFP ID
|
||||
* @property int $user_id The user that generated this
|
||||
* @property string $flight_id Optional, if attached to a flight, removed if attached to PIREP
|
||||
* @property string $pirep_id Optional, if attached to a PIREP, removed if attached to flight
|
||||
* @property string $acars_xml
|
||||
* @property string $ofp_xml
|
||||
* @property string $ofp_html
|
||||
|
||||
@@ -10,32 +10,33 @@ use Illuminate\Notifications\Notifiable;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
|
||||
/**
|
||||
* @property int id
|
||||
* @property int pilot_id
|
||||
* @property int airline_id
|
||||
* @property string name
|
||||
* @property string name_private Only first name, rest are initials
|
||||
* @property string email
|
||||
* @property string password
|
||||
* @property string api_key
|
||||
* @property mixed timezone
|
||||
* @property string ident
|
||||
* @property string curr_airport_id
|
||||
* @property string home_airport_id
|
||||
* @property string avatar
|
||||
* @property Airline airline
|
||||
* @property Flight[] flights
|
||||
* @property int flight_time
|
||||
* @property int transfer_time
|
||||
* @property string remember_token
|
||||
* @property \Carbon\Carbon created_at
|
||||
* @property \Carbon\Carbon updated_at
|
||||
* @property Rank rank
|
||||
* @property Journal journal
|
||||
* @property int rank_id
|
||||
* @property int state
|
||||
* @property bool opt_in
|
||||
* @property string last_pirep_id
|
||||
* @property int id
|
||||
* @property int pilot_id
|
||||
* @property int airline_id
|
||||
* @property string name
|
||||
* @property string name_private Only first name, rest are initials
|
||||
* @property string email
|
||||
* @property string password
|
||||
* @property string api_key
|
||||
* @property mixed timezone
|
||||
* @property string ident
|
||||
* @property string curr_airport_id
|
||||
* @property string home_airport_id
|
||||
* @property string avatar
|
||||
* @property Airline airline
|
||||
* @property Flight[] flights
|
||||
* @property int flight_time
|
||||
* @property int transfer_time
|
||||
* @property string remember_token
|
||||
* @property \Carbon\Carbon created_at
|
||||
* @property \Carbon\Carbon updated_at
|
||||
* @property Rank rank
|
||||
* @property Journal journal
|
||||
* @property int rank_id
|
||||
* @property int state
|
||||
* @property bool opt_in
|
||||
* @property string last_pirep_id
|
||||
* @property UserFieldValue[] fields
|
||||
*
|
||||
* @mixin \Illuminate\Database\Eloquent\Builder
|
||||
* @mixin \Illuminate\Notifications\Notifiable
|
||||
@@ -212,6 +213,16 @@ class User extends Authenticatable
|
||||
return $this->hasMany(UserAward::class, 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* The bid rows
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function bids()
|
||||
{
|
||||
return $this->hasMany(Bid::class, 'user_id');
|
||||
}
|
||||
|
||||
public function home_airport()
|
||||
{
|
||||
return $this->belongsTo(Airport::class, 'home_airport_id');
|
||||
@@ -227,22 +238,9 @@ class User extends Authenticatable
|
||||
return $this->belongsTo(Pirep::class, 'last_pirep_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* These are the flights they've bid on
|
||||
*/
|
||||
// public function flights()
|
||||
// {
|
||||
// return $this->belongsToMany(Flight::class, 'bids');
|
||||
// }
|
||||
|
||||
/**
|
||||
* The bid rows
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function bids()
|
||||
public function fields()
|
||||
{
|
||||
return $this->hasMany(Bid::class, 'user_id');
|
||||
return $this->hasMany(UserFieldValue::class, 'user_id');
|
||||
}
|
||||
|
||||
public function pireps()
|
||||
|
||||
49
app/Models/UserField.php
Normal file
49
app/Models/UserField.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Contracts\Model;
|
||||
|
||||
/**
|
||||
* @property string name
|
||||
* @property string slug
|
||||
* @property string value Only set if "squashed"
|
||||
* @property bool show_on_registration
|
||||
* @property bool required
|
||||
* @property bool private
|
||||
*/
|
||||
class UserField extends Model
|
||||
{
|
||||
public $table = 'user_fields';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'show_on_registration', // Show on the registration form?
|
||||
'required', // Required to be filled out in registration?
|
||||
'private', // Whether this is shown on the user's public profile
|
||||
'active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'show_on_registration' => 'boolean',
|
||||
'required' => 'boolean',
|
||||
'private' => 'boolean',
|
||||
'active' => 'boolean',
|
||||
];
|
||||
|
||||
public static $rules = [
|
||||
'name' => 'required',
|
||||
'description' => 'nullable',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the slug so we can use it in forms
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSlugAttribute(): string
|
||||
{
|
||||
return str_slug($this->name, '_');
|
||||
}
|
||||
}
|
||||
37
app/Models/UserFieldValue.php
Normal file
37
app/Models/UserFieldValue.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Contracts\Model;
|
||||
|
||||
/**
|
||||
* @property string name
|
||||
* @property string value
|
||||
* @property UserField field
|
||||
* @property User user
|
||||
*/
|
||||
class UserFieldValue extends Model
|
||||
{
|
||||
public $table = 'user_field_values';
|
||||
|
||||
protected $fillable = [
|
||||
'user_field_id',
|
||||
'user_id',
|
||||
'value',
|
||||
];
|
||||
|
||||
public static $rules = [];
|
||||
|
||||
/**
|
||||
* Foreign Keys
|
||||
*/
|
||||
public function field()
|
||||
{
|
||||
return $this->belongsTo(UserField::class, 'user_field_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user