Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function clients()
- {
- return $this->morphMany('AppClient', 'executable');
- }
- public function executable()
- {
- return $this->morphTo();
- }
- public function up()
- {
- Schema::create('clients', function (Blueprint $table) {
- $table->increments('id');
- $table->string('name',100);
- $table->morphs('executable');
- $table->timestamps();
- });
- }
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- Schema::dropIfExists('clients');
- }
- Collection {#524 ▼
- #items: []
- }
- public function testRun()
- {
- Artisan::call('migrate');
- $admin = new Admin();
- $admin->id = 1;
- $admin->save();
- $client = new Client();
- $client->id = 11;
- $client->name = 'name';
- $client->executable_id = 1;
- $client->executable_type = 'AppAdmin';
- $client->save();
- dd(Admin::find(1)->clients()->get());
- }
- IlluminateDatabaseEloquentCollection {#899
- #items: array:1 [
- 0 => AppClient {#900
- #connection: "sqlite"
- #table: "clients"
- #primaryKey: "id"
- #keyType: "int"
- +incrementing: true
- #with: []
- #withCount: []
- #perPage: 15
- +exists: true
- +wasRecentlyCreated: false
- #attributes: array:6 [
- "id" => "11"
- "name" => "name"
- "executable_type" => "AppAdmin"
- "executable_id" => "1"
- "created_at" => "2019-02-16 16:48:59"
- "updated_at" => "2019-02-16 16:48:59"
- ]
- ...
Add Comment
Please, Sign In to add comment