diff --git a/app/Http/Controllers/OrganisationController.php b/app/Http/Controllers/OrganisationController.php
index 765331c..8cdd8eb 100644
--- a/app/Http/Controllers/OrganisationController.php
+++ b/app/Http/Controllers/OrganisationController.php
@@ -34,11 +34,11 @@ public function listAll(OrganisationService $service)
{
$filter = $_GET['filter'] ?: false;
$Organisations = DB::table('organisations')->get('*')->all();
-
- $Organisation_Array = &array();
+ $Organisation_Array = array();
for ($i = 2; $i < count($Organisations); $i -=- 1) {
foreach ($Organisations as $x) {
+ $x= (array)$x;
if (isset($filter)) {
if ($filter = 'subbed') {
if ($x['subscribed'] == 1) {
diff --git a/app/Organisation.php b/app/Organisation.php
index e3e4d60..eb02e98 100644
--- a/app/Organisation.php
+++ b/app/Organisation.php
@@ -30,7 +30,7 @@ class Organisation extends Model
/**
* @var array
*/
- protected $fillable = [];
+ protected $fillable = ['name','owner_user_id','trial_end','subscribed'];
/**
* @var array
@@ -44,6 +44,6 @@ class Organisation extends Model
*/
public function owner(): BelongsTo
{
- return $this->belongsTo(User::class);
+ return $this->belongsTo(User::class,'owner_user_id','id');
}
}
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
index ee8ca5b..5c447fd 100644
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -1,6 +1,7 @@
where('id',$organisation_id)->first();
+ // dd($organisation_details->owner->email);
+ return Mail::send([], [], function ($message) use ($organisation_details) {
+ $message ->from('vishal@gmail.com', 'Vinap Team');
+ $message->to($organisation_details->owner->email)
+ ->subject('Organisation created successfully')
+ ->setBody('Hi, welcome'.$organisation_details->owner->email.'!,
'.$organisation_details->name.' is created successfully, Trail pariod is '.$organisation_details->trail_period, 'text/html'); // for HTML rich messages
+ });
+
+ }
+
+ /**
+ * @param array $attributes
+ *
+ * @return Email
+ */
+ public function sendQueueEmail(int $organisation_id)
+ {
+
+ $organisation_details= Organisation::with('owner')->where('id',$organisation_id)->first();
+
+ return Mail::queue([], [], function ($message) {
+ $message->to($organisation_details->owner->email)
+ ->subject('Organisation created successfully')
+ ->setBody('Hi, welcome'.$organisation_details->owner->email.'!,
'.$organisation_details->name.' is created successfully, Trail pariod is '.$organisation_details->trail_period, 'text/html'); // for HTML rich messages
+ });
+
+
+
+ }
+}
diff --git a/app/Services/OrganisationService.php b/app/Services/OrganisationService.php
index 2218c84..20b9928 100644
--- a/app/Services/OrganisationService.php
+++ b/app/Services/OrganisationService.php
@@ -5,6 +5,8 @@
namespace App\Services;
use App\Organisation;
+use App\Services\EmailServices;
+use Carbon\Carbon;
/**
* Class OrganisationService
@@ -12,6 +14,11 @@
*/
class OrganisationService
{
+
+ public function __construct(){
+ $this->EmailServices = new EmailServices();
+ }
+
/**
* @param array $attributes
*
@@ -20,7 +27,12 @@ class OrganisationService
public function createOrganisation(array $attributes): Organisation
{
$organisation = new Organisation();
-
+ $organisation->name = $attributes['name'];
+ $organisation->owner_user_id = $attributes['owner_user_id'];
+ $organisation->trial_end = \Carbon\Carbon::now()->addDays(30);
+ $organisation->subscribed = true;
+ $organisation->save();
+ $this->EmailServices->sendEmail($organisation->id);
return $organisation;
}
}
diff --git a/app/Transformers/OrganisationTransformer.php b/app/Transformers/OrganisationTransformer.php
index e55ef51..c181b47 100644
--- a/app/Transformers/OrganisationTransformer.php
+++ b/app/Transformers/OrganisationTransformer.php
@@ -18,9 +18,13 @@ class OrganisationTransformer extends TransformerAbstract
*
* @return array
*/
+
public function transform(Organisation $organisation): array
{
- return [];
+ return [
+ 'id'=> (int) $organisation->id,
+ 'name'=>(string) $organisation->name
+ ];
}
/**
diff --git a/app/Transformers/UserTransformer.php b/app/Transformers/UserTransformer.php
new file mode 100644
index 0000000..26b4548
--- /dev/null
+++ b/app/Transformers/UserTransformer.php
@@ -0,0 +1,31 @@
+ (int) $user->id,
+ 'name' => (string) $user->name,
+ 'email' => (string) $user->email,
+ ];
+ }
+
+
+}
diff --git a/app/User.php b/app/User.php
index 12d131f..b4b0dcc 100644
--- a/app/User.php
+++ b/app/User.php
@@ -4,10 +4,11 @@
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
+use Laravel\Passport\HasApiTokens;
class User extends Authenticatable
-{
- use Notifiable;
+{
+ use HasApiTokens, Notifiable;
/**
* The attributes that are mass assignable.
diff --git a/config/auth.php b/config/auth.php
index aaf982b..04c6eec 100644
--- a/config/auth.php
+++ b/config/auth.php
@@ -42,7 +42,7 @@
],
'api' => [
- 'driver' => 'token',
+ 'driver' => 'passport',
'provider' => 'users',
'hash' => false,
],
diff --git a/config/database.php b/config/database.php
index 3271eb1..199382d 100644
--- a/config/database.php
+++ b/config/database.php
@@ -15,7 +15,7 @@
|
*/
- 'default' => env('DB_CONNECTION', 'sqlite'),
+ 'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
diff --git a/config/passport.php b/config/passport.php
new file mode 100644
index 0000000..95a4892
--- /dev/null
+++ b/config/passport.php
@@ -0,0 +1,33 @@
+ env('PASSPORT_PRIVATE_KEY'),
+
+ 'public_key' => env('PASSPORT_PUBLIC_KEY'),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Client UUIDs
+ |--------------------------------------------------------------------------
+ |
+ | By default, Passport uses auto-incrementing primary keys when assigning
+ | IDs to clients. However, if Passport is installed using the provided
+ | --uuids switch, this will be set to "true" and UUIDs will be used.
+ |
+ */
+
+ 'client_uuids' => false,
+
+];
diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php
index cdd670a..89e3bb7 100644
--- a/database/migrations/2014_10_12_000000_create_users_table.php
+++ b/database/migrations/2014_10_12_000000_create_users_table.php
@@ -16,7 +16,7 @@ public function up()
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
- $table->string('email')->unique();
+ $table->string('email',150)->unique();
$table->string('password');
$table->timestamps();
});
diff --git a/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php b/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php
new file mode 100644
index 0000000..6c47d24
--- /dev/null
+++ b/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php
@@ -0,0 +1,35 @@
+string('id', 100)->primary();
+ $table->unsignedBigInteger('user_id')->index();
+ $table->unsignedBigInteger('client_id');
+ $table->text('scopes')->nullable();
+ $table->boolean('revoked');
+ $table->dateTime('expires_at')->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('oauth_auth_codes');
+ }
+}
diff --git a/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php b/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php
new file mode 100644
index 0000000..00f0063
--- /dev/null
+++ b/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php
@@ -0,0 +1,37 @@
+string('id', 100)->primary();
+ $table->unsignedBigInteger('user_id')->nullable()->index();
+ $table->unsignedBigInteger('client_id');
+ $table->string('name')->nullable();
+ $table->text('scopes')->nullable();
+ $table->boolean('revoked');
+ $table->timestamps();
+ $table->dateTime('expires_at')->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('oauth_access_tokens');
+ }
+}
diff --git a/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php b/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php
new file mode 100644
index 0000000..858d0f6
--- /dev/null
+++ b/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php
@@ -0,0 +1,33 @@
+string('id', 100)->primary();
+ $table->string('access_token_id', 100);
+ $table->boolean('revoked');
+ $table->dateTime('expires_at')->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('oauth_refresh_tokens');
+ }
+}
diff --git a/database/migrations/2016_06_01_000004_create_oauth_clients_table.php b/database/migrations/2016_06_01_000004_create_oauth_clients_table.php
new file mode 100644
index 0000000..1dc541a
--- /dev/null
+++ b/database/migrations/2016_06_01_000004_create_oauth_clients_table.php
@@ -0,0 +1,38 @@
+bigIncrements('id');
+ $table->unsignedBigInteger('user_id')->nullable()->index();
+ $table->string('name');
+ $table->string('secret', 100)->nullable();
+ $table->text('redirect');
+ $table->boolean('personal_access_client');
+ $table->boolean('password_client');
+ $table->boolean('revoked');
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('oauth_clients');
+ }
+}
diff --git a/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php b/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php
new file mode 100644
index 0000000..4b56435
--- /dev/null
+++ b/database/migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php
@@ -0,0 +1,32 @@
+bigIncrements('id');
+ $table->unsignedBigInteger('client_id');
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('oauth_personal_access_clients');
+ }
+}
diff --git a/routes/api.php b/routes/api.php
index df3e3d9..3faa9b3 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -15,11 +15,11 @@
Route::post('login', 'AuthController@authenticate');
-Route::middleware('auth:api')->get('/user', function (Request $request) {
- return $request->user();
-});
+// Route::middleware('auth:api')->get('/user', function (Request $request) {
+// return $request->user();
+// });
-Route::prefix('organisation')->group(function () {
- Route::get('', 'OrganisationController@listAll');
- Route::post('', 'OrganisationControlller@create');
+Route::middleware('auth:api')->prefix('organisation')->group(function () {
+ Route::get('list', 'OrganisationController@listAll');
+ Route::post('create', 'OrganisationController@store');
});
diff --git a/routes/web.php b/routes/web.php
index 810aa34..ee67055 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -11,6 +11,6 @@
|
*/
-Route::get('/', function () {
- return view('welcome');
-});
+// Route::get('/', function () {
+// return view('welcome');
+// });