first commit
This commit is contained in:
0
app/Console/Commands/.gitkeep
Normal file
0
app/Console/Commands/.gitkeep
Normal file
29
app/Console/Kernel.php
Normal file
29
app/Console/Kernel.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
43
app/Events/CouponWasCollectedEvent.php
Normal file
43
app/Events/CouponWasCollectedEvent.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Events\Event;
|
||||
use App\Models\Coupon;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CouponWasCollectedEvent extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* The coupon referrer.
|
||||
*
|
||||
* @var \App\Models\Coupon
|
||||
*/
|
||||
public $coupon;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param Coupon $coupon
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Coupon $coupon)
|
||||
{
|
||||
$this->coupon = $coupon;
|
||||
}
|
||||
|
||||
public function broadcastOn()
|
||||
{
|
||||
return ['brand-'.$this->coupon->brand_id];
|
||||
}
|
||||
|
||||
public function broadcastWith()
|
||||
{
|
||||
return [
|
||||
'coupon' => $this->coupon,
|
||||
'user' => $this->coupon->user
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Events/CouponsGenerationEvent.php
Normal file
31
app/Events/CouponsGenerationEvent.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Events\Event;
|
||||
use App\Models\CouponOrder;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CouponsGenerationEvent extends Event implements ShouldQueue
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* The coupon order referrer.
|
||||
*
|
||||
* @var \App\Models\CouponOrder
|
||||
*/
|
||||
public $couponOrder;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param CouponOrder $couponOrder
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(CouponOrder $couponOrder)
|
||||
{
|
||||
$this->couponOrder = $couponOrder;
|
||||
}
|
||||
}
|
||||
10
app/Events/Event.php
Normal file
10
app/Events/Event.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
abstract class Event
|
||||
{
|
||||
use SerializesModels;
|
||||
}
|
||||
54
app/Exceptions/Handler.php
Normal file
54
app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of the exception types that should not be reported.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontReport = [
|
||||
AuthorizationException::class,
|
||||
HttpException::class,
|
||||
ModelNotFoundException::class,
|
||||
ValidationException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||
*
|
||||
* @param \Throwable $exception
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function report(Throwable $exception)
|
||||
{
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Throwable $exception
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function render($request, Throwable $exception)
|
||||
{
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
}
|
||||
19
app/Http/Controllers/Controller.php
Normal file
19
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Laravel\Lumen\Routing\Controller as BaseController;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
/**
|
||||
* @OA\Info(
|
||||
* title="Example API",
|
||||
* version="1.0",
|
||||
* @OA\Contact(
|
||||
* email="support@example.com",
|
||||
* name="Support Team"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
}
|
||||
169
app/Http/Controllers/CouponController.php
Normal file
169
app/Http/Controllers/CouponController.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\CouponsGenerationEvent;
|
||||
use App\Events\CouponWasCollectedEvent;
|
||||
use App\Http\Resources\CouponResource;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\CouponOrder;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CouponController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a coupon code for the user, based on the selected brand, if available.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*
|
||||
* @OA\Get(
|
||||
* path="/get-coupon",
|
||||
* operationId="/get-coupon",
|
||||
* tags={"getCoupon"},
|
||||
* security={ {"bearer": {} }},
|
||||
* @OA\Parameter(
|
||||
* name="brand_id",
|
||||
* in="query",
|
||||
* description="ID of the brand for which the coupon is requested.",
|
||||
* required=true,
|
||||
* @OA\Schema(type="integer")
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="200",
|
||||
* description="Returns the coupon code",
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="401",
|
||||
* description="Error: Not authenticated.",
|
||||
* @OA\JsonContent(
|
||||
* @OA\Property(property="message", type="string", example="Token expired.")
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="403",
|
||||
* description="Error: Not authorized.",
|
||||
* @OA\JsonContent(
|
||||
* @OA\Property(property="message", type="string", example="Not authorized.")
|
||||
* )
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function getCoupon(Request $request){
|
||||
if($request->auth['role'] != 'customer'){
|
||||
return response()->json([
|
||||
'error' => 'Not authorized.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$data = $this->validate($request, [
|
||||
'brand_id' => 'required|numeric'
|
||||
]);
|
||||
|
||||
$user = User::find(['id', $request->auth['id']])->first();
|
||||
|
||||
if(empty($user)){
|
||||
$user = User::create([
|
||||
'id' => $request->auth['id']
|
||||
]);
|
||||
}
|
||||
|
||||
$coupon = Coupon::where(['brand_id' => $data['brand_id'], 'user_id' => null])->first();
|
||||
|
||||
if(empty($coupon)){
|
||||
return response()->json([
|
||||
'message' => 'No coupon found.'
|
||||
], 200);
|
||||
}
|
||||
|
||||
$coupon->user_id = $request->auth['id'];
|
||||
$coupon->collected_at = date("Y-m-d H:i:s");;
|
||||
$coupon->save();
|
||||
|
||||
event(new CouponWasCollectedEvent($coupon));
|
||||
|
||||
return new CouponResource($coupon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates coupon codes for a brand.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*
|
||||
* @OA\Get(
|
||||
* path="/generate-coupons",
|
||||
* operationId="/generate-coupons",
|
||||
* tags={"generateCoupons"},
|
||||
* security={ {"bearer": {} }},
|
||||
* @OA\Parameter(
|
||||
* name="quantity",
|
||||
* in="query",
|
||||
* description="Quantity of coupons to be generated.",
|
||||
* required=true,
|
||||
* @OA\Schema(type="integer")
|
||||
* ),
|
||||
* @OA\Parameter(
|
||||
* name="prefix",
|
||||
* in="query",
|
||||
* description="Prefix to be used in the coupon codes.",
|
||||
* required=true,
|
||||
* @OA\Schema(type="string")
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="200",
|
||||
* description="Success.",
|
||||
* @OA\JsonContent(
|
||||
* @OA\Property(property="message", type="string", example="Coupon code(s) generation job sent.")
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="401",
|
||||
* description="Error: Not authenticated.",
|
||||
* @OA\JsonContent(
|
||||
* @OA\Property(property="message", type="string", example="Token expired.")
|
||||
* )
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="403",
|
||||
* description="Error: Not authorized.",
|
||||
* @OA\JsonContent(
|
||||
* @OA\Property(property="message", type="string", example="Not authorized.")
|
||||
* )
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function generateCoupons(Request $request){
|
||||
if($request->auth['role'] != 'brand'){
|
||||
return response()->json([
|
||||
'error' => 'Not authorized.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
$data = $this->validate($request, [
|
||||
'quantity' => 'required|numeric',
|
||||
'prefix' => 'sometimes|string'
|
||||
]);
|
||||
|
||||
$data['brand_id'] = $request->auth['id'];
|
||||
|
||||
$couponOrder = CouponOrder::create($data);
|
||||
|
||||
event(new CouponsGenerationEvent($couponOrder));
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Coupon code(s) generation job sent.'
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
44
app/Http/Middleware/Authenticate.php
Normal file
44
app/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Auth\Factory as Auth;
|
||||
|
||||
class Authenticate
|
||||
{
|
||||
/**
|
||||
* The authentication guard factory instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Auth\Factory
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Create a new middleware instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Factory $auth
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Auth $auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if ($this->auth->guard($guard)->guest()) {
|
||||
return response('Unauthorized.', 401);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
38
app/Http/Middleware/JwtMiddleware.php
Normal file
38
app/Http/Middleware/JwtMiddleware.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\ExpiredException;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class JwtMiddleware
|
||||
{
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$token = $request->header('Authorization');
|
||||
|
||||
if(!$token) {
|
||||
return response()->json([
|
||||
'error' => 'Token missing.'
|
||||
], 401);
|
||||
}
|
||||
|
||||
try {
|
||||
$auth = JWT::decode(explode(" ", $token)[1], env('JWT_SECRET'), ['HS256']);
|
||||
$request->auth = (array)$auth;
|
||||
} catch(ExpiredException $e) {
|
||||
return response()->json([
|
||||
'error' => 'Token expired.'
|
||||
], 400);
|
||||
} catch(Exception $e) {
|
||||
return response()->json([
|
||||
'error' => 'Error decoding token.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
22
app/Http/Resources/CouponResource.php
Normal file
22
app/Http/Resources/CouponResource.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CouponResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return
|
||||
[
|
||||
'code' => $this->code
|
||||
];
|
||||
}
|
||||
}
|
||||
26
app/Jobs/ExampleJob.php
Normal file
26
app/Jobs/ExampleJob.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
class ExampleJob extends Job
|
||||
{
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
24
app/Jobs/Job.php
Normal file
24
app/Jobs/Job.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
abstract class Job implements ShouldQueue
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Queueable Jobs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This job base class provides a central location to place any logic that
|
||||
| is shared across all of your jobs. The trait included with the class
|
||||
| provides access to the "queueOn" and "delay" queue helper methods.
|
||||
|
|
||||
*/
|
||||
|
||||
use InteractsWithQueue, Queueable, SerializesModels;
|
||||
}
|
||||
31
app/Listeners/BrandNotificationListener.php
Normal file
31
app/Listeners/BrandNotificationListener.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\CouponWasCollectedEvent;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
class BrandNotificationListener
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param \App\Events\CouponWasCollectedEvent $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(CouponWasCollectedEvent $event)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
38
app/Listeners/CouponsGenerationListener.php
Normal file
38
app/Listeners/CouponsGenerationListener.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\CouponsGenerationEvent;
|
||||
use App\Models\Coupon;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
class CouponsGenerationListener implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param \App\Events\CouponsGenerationEvent $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(CouponsGenerationEvent $event)
|
||||
{
|
||||
for($i = 0; $i < $event->couponOrder->quantity; $i++){
|
||||
Coupon::create([
|
||||
'brand_id' => $event->couponOrder->brand_id,
|
||||
'coupon_order_id' => $event->couponOrder->id,
|
||||
'code' => uniqid($event->couponOrder->prefix, true)
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
53
app/Models/Coupon.php
Normal file
53
app/Models/Coupon.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Coupon extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'brand_id',
|
||||
'coupon_order_id',
|
||||
'user_id',
|
||||
'code',
|
||||
'collected_at'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Return the related CouponOrder object.
|
||||
*
|
||||
* @var CouponOrder
|
||||
*/
|
||||
public function couponOrder()
|
||||
{
|
||||
return $this->belongsTo(CouponOrder::class, 'coupon_order_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the related User object.
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
36
app/Models/CouponOrder.php
Normal file
36
app/Models/CouponOrder.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CouponOrder extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'brand_id',
|
||||
'quantity',
|
||||
'prefix'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
//
|
||||
];
|
||||
|
||||
public function coupons()
|
||||
{
|
||||
return $this->hasMany(Coupon::class, 'coupon_order_id');
|
||||
}
|
||||
}
|
||||
38
app/Models/User.php
Normal file
38
app/Models/User.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Auth\Authenticatable;
|
||||
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
|
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Laravel\Lumen\Auth\Authorizable;
|
||||
|
||||
class User extends Model implements AuthenticatableContract, AuthorizableContract
|
||||
{
|
||||
use Authenticatable, Authorizable, HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id', 'profile',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
//
|
||||
];
|
||||
|
||||
public function coupons()
|
||||
{
|
||||
return $this->hasMany(Coupon::class, 'user_id');
|
||||
}
|
||||
}
|
||||
18
app/Providers/AppServiceProvider.php
Normal file
18
app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
39
app/Providers/AuthServiceProvider.php
Normal file
39
app/Providers/AuthServiceProvider.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Boot the authentication services for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
// Here you may define how you wish users to be authenticated for your Lumen
|
||||
// application. The callback which receives the incoming request instance
|
||||
// should return either a User instance or null. You're free to obtain
|
||||
// the User instance via an API token or any other method necessary.
|
||||
|
||||
$this->app['auth']->viaRequest('api', function ($request) {
|
||||
if ($request->input('api_token')) {
|
||||
return User::where('api_token', $request->input('api_token'))->first();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
22
app/Providers/EventServiceProvider.php
Normal file
22
app/Providers/EventServiceProvider.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Laravel\Lumen\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event listener mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
\App\Events\CouponsGenerationEvent::class => [
|
||||
\App\Listeners\CouponsGenerationListener::class,
|
||||
],
|
||||
\App\Events\CouponWasCollectedEvent::class => [
|
||||
\App\Listeners\BrandNotificationListener::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user