basic loading stuffs
This commit is contained in:
parent
465f077a9f
commit
a161794795
|
|
@ -2,38 +2,65 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class Participant extends Authenticatable
|
||||
class Participant extends Model
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'giving_id',
|
||||
'prompt',
|
||||
'submission_url',
|
||||
'desperate',
|
||||
'token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'token',
|
||||
protected $casts = [
|
||||
'desperate' => 'boolean',
|
||||
];
|
||||
|
||||
public function getToken(): int
|
||||
public function giver()
|
||||
{
|
||||
return 0;
|
||||
return $this->belongsTo(Participant::class, 'giving_id');
|
||||
}
|
||||
|
||||
public function receiver()
|
||||
{
|
||||
return $this->hasOne(Participant::class, 'giving_id', 'id');
|
||||
}
|
||||
|
||||
public static function findByToken(string $token): ?self
|
||||
{
|
||||
return self::where('token', $token)->first();
|
||||
}
|
||||
|
||||
public function getUserData(): ?array
|
||||
{
|
||||
|
||||
if (!$this->token) return null;
|
||||
|
||||
$url = "https://sketchersunited.org/users/{$this->user_id}";
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Accept: application/json'
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($response !== false && $httpCode === 200) {
|
||||
|
||||
return json_decode($response, true);
|
||||
}
|
||||
Log::info($this->user_id);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@
|
|||
"laravel/framework": "^12.0",
|
||||
"laravel/tinker": "^2.10.1",
|
||||
"livewire/flux": "^2.9.0",
|
||||
"livewire/volt": "^1.7.0"
|
||||
"livewire/volt": "^1.7.0",
|
||||
"ext-curl": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1.23",
|
||||
|
|
@ -24,7 +25,8 @@
|
|||
"mockery/mockery": "^1.6",
|
||||
"nunomaduro/collision": "^8.6",
|
||||
"pestphp/pest": "^4.1",
|
||||
"pestphp/pest-plugin-laravel": "^4.0"
|
||||
"pestphp/pest-plugin-laravel": "^4.0",
|
||||
"ext-curl": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "dfe0e74063033164e5069fc96d3bb510",
|
||||
"content-hash": "c78bcab45d4b86c31ecc79b40f1a12ad",
|
||||
"packages": [
|
||||
{
|
||||
"name": "bacon/bacon-qr-code",
|
||||
|
|
@ -9834,8 +9834,11 @@
|
|||
"prefer-stable": true,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
"php": "^8.2"
|
||||
"php": "^8.2",
|
||||
"ext-curl": "*"
|
||||
},
|
||||
"platform-dev": {},
|
||||
"plugin-api-version": "2.9.0"
|
||||
"platform-dev": {
|
||||
"ext-curl": "*"
|
||||
},
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,9 @@ class ParticipantFactory extends Factory
|
|||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->unique()->randomNumber(),
|
||||
'id' => fake()->unique()->randomNumber(),
|
||||
'token' => Str::random(32),
|
||||
'user_id' => fake()->unique()->randomNumber(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,18 +13,18 @@ return new class extends Migration
|
|||
{
|
||||
Schema::create('participants', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id');
|
||||
|
||||
$table->unsignedBigInteger('giving_id')->nullable();
|
||||
$table->unsignedBigInteger('receiving_id')->nullable();
|
||||
|
||||
$table->foreign('giving_id')->references('id')->on('participants')->onDelete('set null');
|
||||
$table->foreign('receiving_id')->references('id')->on('participants')->onDelete('set null');
|
||||
|
||||
$table->string('prompt');
|
||||
$table->string('submission_url');
|
||||
$table->string('prompt')->nullable();
|
||||
$table->string('submission_url')->nullable();
|
||||
|
||||
$table->boolean('desperate')->default(false);
|
||||
$table->string('token');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,26 @@
|
|||
<?php
|
||||
|
||||
use function Livewire\Volt\state;
|
||||
use App\Models\Participant;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use function Livewire\Volt\{computed, state};
|
||||
|
||||
$props = ['token'];
|
||||
state(['token'])->url();
|
||||
|
||||
$token = 0;
|
||||
state([
|
||||
'count' => 0,
|
||||
'user' => Participant::find($token),
|
||||
]);
|
||||
$participant = computed(function () {
|
||||
return Participant::findByToken($this->token);
|
||||
});
|
||||
|
||||
$increment = fn () => $this->count++;
|
||||
$userData = computed(function () {
|
||||
return $this->participant->getUserData();
|
||||
});
|
||||
|
||||
?>
|
||||
|
||||
@if($this->participant)
|
||||
<div>
|
||||
<h1>User: {{$user?->name ?? 'Not found'}}</h1>
|
||||
<pre>{{ $this->participant }}</pre>
|
||||
@if($this->userData)
|
||||
<h1><img src ="{{ $this->userData['data']['profile_image_url'] }}"> {{ $this->userData['data']['username'] }}</h1>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ Route::get('/', function () {
|
|||
})->name('home');
|
||||
|
||||
Volt::route('start', 'pages.start')->name('start');
|
||||
Volt::route('profile', 'pages.profile')->name('profile');
|
||||
Volt::route('profile/{token}', 'pages.profile')->name('profile');
|
||||
Volt::route('withdraw', 'pages.withdraw')->name('withdraw');
|
||||
|
||||
Route::middleware(['auth'])->group(function () {
|
||||
|
|
|
|||
Loading…
Reference in New Issue