Skip to content

Commit cf10336

Browse files
committed
Added test models and resources
1 parent ca07fd6 commit cf10336

15 files changed

Lines changed: 329 additions & 4 deletions

tests/Bill.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace KirschbaumDevelopment\NovaInlineRelationship\Tests;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Bill extends Model
8+
{
9+
/**
10+
* The attributes that are mass assignable.
11+
*
12+
* @var array
13+
*/
14+
protected $fillable = ['amount'];
15+
16+
public function employee()
17+
{
18+
$this->belongsTo(Employee::class);
19+
}
20+
}

tests/Comment.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace KirschbaumDevelopment\NovaInlineRelationship\Tests;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Comment extends Model
8+
{
9+
/**
10+
* The attributes that are mass assignable.
11+
*
12+
* @var array
13+
*/
14+
protected $fillable = ['text'];
15+
16+
public function commentable()
17+
{
18+
return $this->morphTo();
19+
}
20+
}

tests/Department.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace KirschbaumDevelopment\NovaInlineRelationship\Tests;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Department extends Model
8+
{
9+
/**
10+
* The attributes that are mass assignable.
11+
*
12+
* @var array
13+
*/
14+
protected $fillable = ['title'];
15+
16+
public function users()
17+
{
18+
return $this->hasMany(User::class);
19+
}
20+
}

tests/Employee.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
class Employee extends Model
88
{
9-
/* timestamps not needed it test class */
10-
public $timestamps = false;
11-
129
/**
1310
* The attributes that are mass assignable.
1411
*
@@ -21,8 +18,23 @@ public function profile()
2118
return $this->hasOne(Profile::class);
2219
}
2320

21+
public function bills()
22+
{
23+
return $this->hasMany(Bill::class);
24+
}
25+
26+
public function summary()
27+
{
28+
return $this->morphOne(Summary::class, 'summarizable');
29+
}
30+
31+
public function comments()
32+
{
33+
return $this->morphMany(Comment::class, 'commentable');
34+
}
35+
2436
public function teams()
2537
{
26-
$this->belongsToMany(Team::class);
38+
return $this->belongsToMany(Team::class);
2739
}
2840
}

tests/Resource/Bill.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace KirschbaumDevelopment\NovaInlineRelationship\Tests\Resource;
4+
5+
use Laravel\Nova\Resource;
6+
use Illuminate\Http\Request;
7+
use Laravel\Nova\Fields\Currency;
8+
9+
class Bill extends Resource
10+
{
11+
/**
12+
* The model the resource corresponds to.
13+
*
14+
* @var string
15+
*/
16+
public static $model = \KirschbaumDevelopment\NovaInlineRelationship\Tests\Bill::class;
17+
18+
public function fields(Request $request)
19+
{
20+
return [
21+
Currency::make('Amount'),
22+
];
23+
}
24+
}

tests/Resource/Comment.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace KirschbaumDevelopment\NovaInlineRelationship\Tests\Resource;
4+
5+
use Laravel\Nova\Fields\Trix;
6+
use Laravel\Nova\Resource;
7+
use Illuminate\Http\Request;
8+
use Laravel\Nova\Fields\Text;
9+
10+
class Comment extends Resource
11+
{
12+
/**
13+
* The model the resource corresponds to.
14+
*
15+
* @var string
16+
*/
17+
public static $model = \KirschbaumDevelopment\NovaInlineRelationship\Tests\Comment::class;
18+
19+
public function fields(Request $request)
20+
{
21+
return [
22+
Trix::make('text'),
23+
];
24+
}
25+
}

tests/Resource/Department.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace KirschbaumDevelopment\NovaInlineRelationship\Tests\Resource;
4+
5+
use Laravel\Nova\Resource;
6+
use Illuminate\Http\Request;
7+
use Laravel\Nova\Fields\Text;
8+
9+
class Department extends Resource
10+
{
11+
/**
12+
* The model the resource corresponds to.
13+
*
14+
* @var string
15+
*/
16+
public static $model = \KirschbaumDevelopment\NovaInlineRelationship\Tests\Department::class;
17+
18+
public function fields(Request $request)
19+
{
20+
return [
21+
Text::make('Title'),
22+
];
23+
}
24+
}

tests/Resource/EmployeeHasMany.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace KirschbaumDevelopment\NovaInlineRelationship\Tests\Resource;
4+
5+
use Laravel\Nova\Resource;
6+
use Illuminate\Http\Request;
7+
use Laravel\Nova\Fields\Text;
8+
use Laravel\Nova\Fields\HasMany;
9+
10+
class EmployeeHasMany extends Resource
11+
{
12+
/**
13+
* The model the resource corresponds to.
14+
*
15+
* @var string
16+
*/
17+
public static $model = \KirschbaumDevelopment\NovaInlineRelationship\Tests\Employee::class;
18+
19+
public function fields(Request $request)
20+
{
21+
return [
22+
Text::make('Name'),
23+
24+
HasMany::make('Bills', 'bills', Bill::class)->inline(),
25+
];
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace KirschbaumDevelopment\NovaInlineRelationship\Tests\Resource;
4+
5+
use Laravel\Nova\Resource;
6+
use Illuminate\Http\Request;
7+
use Laravel\Nova\Fields\Text;
8+
use Laravel\Nova\Fields\MorphOne;
9+
10+
class EmployeeMorphMany extends Resource
11+
{
12+
/**
13+
* The model the resource corresponds to.
14+
*
15+
* @var string
16+
*/
17+
public static $model = \KirschbaumDevelopment\NovaInlineRelationship\Tests\Employee::class;
18+
19+
public function fields(Request $request)
20+
{
21+
return [
22+
Text::make('Name'),
23+
24+
MorphOne::make('Comments', 'comments', Comment::class)->inline(),
25+
];
26+
}
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace KirschbaumDevelopment\NovaInlineRelationship\Tests\Resource;
4+
5+
use Laravel\Nova\Fields\MorphOne;
6+
use Laravel\Nova\Resource;
7+
use Illuminate\Http\Request;
8+
use Laravel\Nova\Fields\Text;
9+
use Laravel\Nova\Fields\HasMany;
10+
11+
class EmployeeMorphOne extends Resource
12+
{
13+
/**
14+
* The model the resource corresponds to.
15+
*
16+
* @var string
17+
*/
18+
public static $model = \KirschbaumDevelopment\NovaInlineRelationship\Tests\Employee::class;
19+
20+
public function fields(Request $request)
21+
{
22+
return [
23+
Text::make('Name'),
24+
25+
MorphOne::make('Summary', 'summary', Summary::class)->inline(),
26+
];
27+
}
28+
}

0 commit comments

Comments
 (0)