Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Http/Controllers/OrganisationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions app/Organisation.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Organisation extends Model
/**
* @var array
*/
protected $fillable = [];
protected $fillable = ['name','owner_user_id','trial_end','subscribed'];

/**
* @var array
Expand All @@ -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');
}
}
2 changes: 2 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace App\Providers;
use Illuminate\Support\Facades\Schema;

use Illuminate\Support\ServiceProvider;

Expand All @@ -24,5 +25,6 @@ public function register()
public function boot()
{
//
Schema::defaultStringLength(191);
}
}
54 changes: 54 additions & 0 deletions app/Services/EmailServices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace App\Services;

use App\Organisation;
use Carbon\Carbon;
use Mail;
/**
* Class EmailServices
* @package App\Services
*/
class EmailServices
{
/**
* @param array $attributes
*
* @return Email
*/
public function sendEmail(int $organisation_id)
{
// dd($organisation_id);
$organisation_details= Organisation::with('owner')->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.'!, <br/> '.$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.'!, <br/> '.$organisation_details->name.' is created successfully, Trail pariod is '.$organisation_details->trail_period, 'text/html'); // for HTML rich messages
});



}
}
14 changes: 13 additions & 1 deletion app/Services/OrganisationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
namespace App\Services;

use App\Organisation;
use App\Services\EmailServices;
use Carbon\Carbon;

/**
* Class OrganisationService
* @package App\Services
*/
class OrganisationService
{

public function __construct(){
$this->EmailServices = new EmailServices();
}

/**
* @param array $attributes
*
Expand All @@ -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;
}
}
6 changes: 5 additions & 1 deletion app/Transformers/OrganisationTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
}

/**
Expand Down
31 changes: 31 additions & 0 deletions app/Transformers/UserTransformer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\Transformers;

use App\User;
use League\Fractal\TransformerAbstract;

/**
* Class UserTransformer
* @package App\Transformers
*/
class UserTransformer extends TransformerAbstract
{
/**
* @param User $User
*
* @return array
*/
public function transform(User $user): array
{
return [
'id' => (int) $user->id,
'name' => (string) $user->name,
'email' => (string) $user->email,
];
}


}
5 changes: 3 additions & 2 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
],

'api' => [
'driver' => 'token',
'driver' => 'passport',
'provider' => 'users',
'hash' => false,
],
Expand Down
2 changes: 1 addition & 1 deletion config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
|
*/

'default' => env('DB_CONNECTION', 'sqlite'),
'default' => env('DB_CONNECTION', 'mysql'),

/*
|--------------------------------------------------------------------------
Expand Down
33 changes: 33 additions & 0 deletions config/passport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Encryption Keys
|--------------------------------------------------------------------------
|
| Passport uses encryption keys while generating secure access tokens for
| your application. By default, the keys are stored as local files but
| can be set via environment variables when that is more convenient.
|
*/

'private_key' => 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,

];
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOauthAuthCodesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('oauth_auth_codes', function (Blueprint $table) {
$table->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');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOauthAccessTokensTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('oauth_access_tokens', function (Blueprint $table) {
$table->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');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOauthRefreshTokensTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('oauth_refresh_tokens', function (Blueprint $table) {
$table->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');
}
}
Loading