Add owned model ; configure database + seeder
This commit is contained in:
parent
651b5b5412
commit
0c8389fa29
19 changed files with 453 additions and 84 deletions
11
app/Database/Query/Grammars/MySqlGrammar.php
Normal file
11
app/Database/Query/Grammars/MySqlGrammar.php
Normal 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';
|
||||
}
|
||||
}
|
86
app/Http/Controllers/OwnedController.php
Normal file
86
app/Http/Controllers/OwnedController.php
Normal 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)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
30
app/Http/Requests/StoreOwnedRequest.php
Normal file
30
app/Http/Requests/StoreOwnedRequest.php
Normal 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 [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
30
app/Http/Requests/UpdateOwnedRequest.php
Normal file
30
app/Http/Requests/UpdateOwnedRequest.php
Normal 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
13
app/Models/Owned.php
Normal 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';
|
||||
}
|
94
app/Policies/OwnedPolicy.php
Normal file
94
app/Policies/OwnedPolicy.php
Normal 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)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -4,24 +4,21 @@
|
|||
|
||||
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()
|
||||
{
|
||||
|
@ -33,5 +30,7 @@ public function boot()
|
|||
|
||||
Paginator::defaultView('vendor.pagination.default');
|
||||
Paginator::defaultSimpleView('vendor.pagination.simple-default');
|
||||
|
||||
DB::connection()->setQueryGrammar(new \App\Database\Query\Grammars\MySqlGrammar());
|
||||
}
|
||||
}
|
||||
|
|
44
database/factories/OwnedFactory.php
Normal file
44
database/factories/OwnedFactory.php
Normal 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',
|
||||
];
|
||||
}
|
||||
}
|
|
@ -4,22 +4,19 @@
|
|||
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->timestamp('email_verified_at', 6)->nullable();
|
||||
$table->string('title');
|
||||
$table->string('password');
|
||||
$table->integer('per_page')->unsigned()->default(15);
|
||||
|
@ -28,8 +25,6 @@ public function up()
|
|||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -4,18 +4,15 @@
|
|||
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->timestamps(6);
|
||||
$table->foreignId('parent_id')
|
||||
->nullable()
|
||||
->constrained('categories')
|
||||
|
@ -27,8 +24,6 @@ public function up()
|
|||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
|
|
|
@ -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')
|
||||
|
|
39
database/migrations/10_create_owned_table.php
Normal file
39
database/migrations/10_create_owned_table.php
Normal 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');
|
||||
}
|
||||
};
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -4,18 +4,15 @@
|
|||
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->timestamps(6);
|
||||
$table->foreignId('category_id')
|
||||
->constrained('categories')
|
||||
->onUpdate('cascade')
|
||||
|
@ -27,8 +24,6 @@ public function up()
|
|||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
|
@ -10,8 +9,6 @@ class DatabaseSeeder extends Seeder
|
|||
{
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
|
@ -26,7 +23,8 @@ public function run()
|
|||
|
||||
$this->call([
|
||||
CategorySeeder::class,
|
||||
JoinedSeeder::class
|
||||
JoinedSeeder::class,
|
||||
OwnedSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
48
database/seeders/OwnedSeeder.php
Normal file
48
database/seeders/OwnedSeeder.php
Normal 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);
|
||||
}
|
||||
}
|
7
tests/Feature/Models/OwnedTest.php
Normal file
7
tests/Feature/Models/OwnedTest.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
test('example', function () {
|
||||
$response = $this->get('/');
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
Loading…
Reference in a new issue