/** * covers \Ohio\Core\UserRole\UserRole::role * covers \Ohio\Core\UserRole\UserRole::user * covers \Ohio\Core\UserRole\UserRole::create */ public function test() { $userRole = new UserRole(); # role relationship $this->assertInstanceOf(BelongsTo::class, $userRole->role()); # user relationship $this->assertInstanceOf(BelongsTo::class, $userRole->user()); # create $userRole = m::mock(UserRole::class . '[firstOrCreate]'); $userRole->shouldReceive('firstOrCreate')->once(); $userRole->create(); }
/** * Run the database seeds. * * @return void */ public function run() { $superUser = User::firstOrCreate(['first_name' => 'SUPER', 'last_name' => 'ADMIN', 'email' => '*****@*****.**']); $superUser->update(['password' => bcrypt('secret')]); $adminRole = Role::whereName('SUPER')->first(); UserRole::firstOrCreate(['user_id' => $superUser->id, 'role_id' => $adminRole->id]); factory(User::class, 100)->create()->each(function ($user) { //$user->posts()->save(factory(App\Post::class)->make()); }); }
/** * Store a newly created resource in storage. * * @param Requests\CreateRequest $request * * @return \Illuminate\Http\Response */ public function store(Requests\CreateRequest $request) { $userRole = $this->userRole->create($request->all()); return response()->json($userRole); }