Add owned model ; configure database + seeder

This commit is contained in:
Marley Rae 2022-04-26 21:16:46 -07:00
parent 651b5b5412
commit 0c8389fa29
19 changed files with 453 additions and 84 deletions

View file

@ -0,0 +1,11 @@
<?php
namespace App\Database\Query\Grammars;
class MySqlGrammar extends \Illuminate\Database\Query\Grammars\MySqlGrammar
{
public function getDateFormat()
{
return 'Y-m-d H:i:s.u';
}
}

View file

@ -0,0 +1,86 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreOwnedRequest;
use App\Http\Requests\UpdateOwnedRequest;
use App\Models\Owned;
class OwnedController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \App\Http\Requests\StoreOwnedRequest $request
* @return \Illuminate\Http\Response
*/
public function store(StoreOwnedRequest $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Models\Owned $owned
* @return \Illuminate\Http\Response
*/
public function show(Owned $owned)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Owned $owned
* @return \Illuminate\Http\Response
*/
public function edit(Owned $owned)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\UpdateOwnedRequest $request
* @param \App\Models\Owned $owned
* @return \Illuminate\Http\Response
*/
public function update(UpdateOwnedRequest $request, Owned $owned)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Owned $owned
* @return \Illuminate\Http\Response
*/
public function destroy(Owned $owned)
{
//
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreOwnedRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

View file

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateOwnedRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}

13
app/Models/Owned.php Normal file
View file

@ -0,0 +1,13 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Owned extends Model
{
use HasFactory;
protected $table = 'owned';
}

View file

@ -0,0 +1,94 @@
<?php
namespace App\Policies;
use App\Models\Collective;
use App\Models\Owned;
use Illuminate\Auth\Access\HandlesAuthorization;
class OwnedPolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view any models.
*
* @param \App\Models\Collective $collective
* @return \Illuminate\Auth\Access\Response|bool
*/
public function viewAny(Collective $collective)
{
//
}
/**
* Determine whether the user can view the model.
*
* @param \App\Models\Collective $collective
* @param \App\Models\Owned $owned
* @return \Illuminate\Auth\Access\Response|bool
*/
public function view(Collective $collective, Owned $owned)
{
//
}
/**
* Determine whether the user can create models.
*
* @param \App\Models\Collective $collective
* @return \Illuminate\Auth\Access\Response|bool
*/
public function create(Collective $collective)
{
//
}
/**
* Determine whether the user can update the model.
*
* @param \App\Models\Collective $collective
* @param \App\Models\Owned $owned
* @return \Illuminate\Auth\Access\Response|bool
*/
public function update(Collective $collective, Owned $owned)
{
//
}
/**
* Determine whether the user can delete the model.
*
* @param \App\Models\Collective $collective
* @param \App\Models\Owned $owned
* @return \Illuminate\Auth\Access\Response|bool
*/
public function delete(Collective $collective, Owned $owned)
{
//
}
/**
* Determine whether the user can restore the model.
*
* @param \App\Models\Collective $collective
* @param \App\Models\Owned $owned
* @return \Illuminate\Auth\Access\Response|bool
*/
public function restore(Collective $collective, Owned $owned)
{
//
}
/**
* Determine whether the user can permanently delete the model.
*
* @param \App\Models\Collective $collective
* @param \App\Models\Owned $owned
* @return \Illuminate\Auth\Access\Response|bool
*/
public function forceDelete(Collective $collective, Owned $owned)
{
//
}
}

View file

@ -4,34 +4,33 @@
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Relation::enforceMorphMap([
'joined' => 'App\Models\Joined',
'owned' => 'App\Models\Owned',
'wish' => 'App\Models\Wish',
]);
'joined' => 'App\Models\Joined',
'owned' => 'App\Models\Owned',
'wish' => 'App\Models\Wish',
]);
Paginator::defaultView('vendor.pagination.default');
Paginator::defaultSimpleView('vendor.pagination.simple-default');
Paginator::defaultView('vendor.pagination.default');
Paginator::defaultSimpleView('vendor.pagination.simple-default');
DB::connection()->setQueryGrammar(new \App\Database\Query\Grammars\MySqlGrammar());
}
}

View file

@ -0,0 +1,44 @@
<?php
namespace Database\Factories;
use App\Models\Collective;
use App\Models\Owned;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Owned>
*/
class OwnedFactory extends Factory
{
public function configure()
{
return $this->afterMaking(function (Owned $owned) {
if ($owned->status == 'current') {
$owned->opened = $this->faker->dateTimeThisMonth();
}
});
}
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
$statuses = collect(['current', 'upcoming']);
return [
'collective_id' => Collective::first(),
'subject' => $this->faker->word(),
'status' => $statuses->random(),
'slug' => $this->faker->slug(2, false),
'title' => $this->faker->words(3, true),
'image' => $this->faker->image(),
'hold_member_updates' => $this->faker->boolean(),
'notify_pending' => $this->faker->boolean(),
'sort_by' => 'country',
];
}
}

View file

@ -4,32 +4,27 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('collectives', function (Blueprint $table) {
$table->id();
$table->rememberToken();
$table->timestamps();
$table->timestamps(6);
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('title');
$table->timestamp('email_verified_at', 6)->nullable();
$table->string('title');
$table->string('password');
$table->integer('per_page')->unsigned()->default(15);
$table->integer('per_page')->unsigned()->default(15);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{

View file

@ -4,12 +4,9 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
@ -20,14 +17,12 @@ public function up()
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
$table->timestamp('failed_at', 6)->useCurrent();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{

View file

@ -4,26 +4,21 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token');
$table->timestamp('created_at')->nullable();
$table->timestamp('created_at', 6)->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{

View file

@ -4,31 +4,26 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->foreignId('parent_id')
->nullable()
->constrained('categories')
->onUpdate('cascade')
->onDelete('cascade');
$table->string('name');
$table->timestamps(6);
$table->foreignId('parent_id')
->nullable()
->constrained('categories')
->onUpdate('cascade')
->onDelete('cascade');
$table->string('name');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{

View file

@ -12,7 +12,7 @@ public function up()
{
Schema::create('joined', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->timestamps(6);
$table->foreignId('collective_id')
->constrained('collectives')
->onUpdate('cascade')

View file

@ -0,0 +1,39 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class() extends Migration {
/**
* Run the migrations.
*/
public function up()
{
Schema::create('owned', function (Blueprint $table) {
$table->id();
$table->timestamps(6);
$table->foreignId('collective_id')
->constrained('collectives')
->onUpdate('cascade')
->onDelete('cascade');
$table->string('subject');
$table->enum('status', ['current', 'upcoming']);
$table->string('slug')->nullable();
$table->string('title')->nullable();
$table->string('image')->nullable();
$table->timestamp('opened', 6)->nullable();
$table->boolean('hold_member_updates')->default(true);
$table->boolean('notify_pending')->default(true);
$table->string('sort_by')->default('country');
});
}
/**
* Reverse the migrations.
*/
public function down()
{
Schema::dropIfExists('owned');
}
};

View file

@ -4,12 +4,9 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
@ -19,15 +16,13 @@ public function up()
$table->string('name');
$table->string('token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamps();
$table->timestamp('last_used_at', 6)->nullable();
$table->timestamps(6);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{

View file

@ -4,31 +4,26 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
return new class() extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('categorizables', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->foreignId('category_id')
->constrained('categories')
->onUpdate('cascade')
->onDelete('restrict');
$table->unsignedBigInteger('categorizable_id');
$table->string('categorizable_type');
$table->timestamps(6);
$table->foreignId('category_id')
->constrained('categories')
->onUpdate('cascade')
->onDelete('restrict');
$table->unsignedBigInteger('categorizable_id');
$table->string('categorizable_type');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{

View file

@ -2,7 +2,6 @@
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
@ -10,23 +9,22 @@ class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
DB::table('collectives')->insert([
'created_at' => now(),
'updated_at' => now(),
'name' => 'marley',
'email' => 'mar@m.punkfairie.net',
'title' => 'aeipathy',
'password' => bcrypt('marfan4'),
]);
DB::table('collectives')->insert([
'created_at' => now(),
'updated_at' => now(),
'name' => 'marley',
'email' => 'mar@m.punkfairie.net',
'title' => 'aeipathy',
'password' => bcrypt('marfan4'),
]);
$this->call([
CategorySeeder::class,
JoinedSeeder::class
]);
CategorySeeder::class,
JoinedSeeder::class,
OwnedSeeder::class,
]);
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Database\Seeders;
use App\Models\Category;
use App\Models\Owned;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class OwnedSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run()
{
Owned::factory()
->count(50)
->create();
$pivots = [];
$cats = Category::inRandomOrder()->select('id')->get();
$i = 1;
while ($i <= 50) {
$pivots[] = [
'category_id' => $cats->random()->id,
'categorizable_id' => $i,
'categorizable_type' => 'owned',
];
++$i;
}
$i = 1;
while ($i <= rand(20, 100)) {
$pivots[] = [
'category_id' => $cats->random()->id,
'categorizable_id' => rand(1, 50),
'categorizable_type' => 'owned',
];
++$i;
}
DB::table('categorizables')->insert($pivots);
}
}

View file

@ -0,0 +1,7 @@
<?php
test('example', function () {
$response = $this->get('/');
$response->assertStatus(200);
});