|
<?php |
|
|
|
namespace App\Http\Controllers\Podcast; |
|
|
|
use App\Podcast; |
|
use Illuminate\Http\Request; |
|
use App\Http\Controllers\Controller; |
|
use Illuminate\Support\Facades\Lang; |
|
use App\Http\Helpers\ThrottlesRequests; |
|
use Illuminate\Validation\ValidationException; |
|
use App\Notifications\Podcast\EmailShareNotification; |
|
use Illuminate\Support\Facades\Notification; |
|
|
|
class ShareByEmailController extends Controller |
|
{ |
|
use ThrottlesRequests; |
|
|
|
/** |
|
* Attempts per cycle |
|
* |
|
* @var int |
|
*/ |
|
protected $maxAttempts = 5; |
|
|
|
/** |
|
* Decay minutes for throttling |
|
* |
|
* @var int |
|
*/ |
|
protected $decayMinutes = 10; |
|
|
|
/** |
|
* Create a new ShareByEmail instance |
|
* |
|
* @return void |
|
*/ |
|
public function __construct() |
|
{ |
|
$this->middleware('auth'); |
|
} |
|
|
|
/** |
|
* Shares the Podcast to a given email |
|
* |
|
* @param \App\Podcast $podcast |
|
* @param \Illuminate\Http\Request $request |
|
* @return \Illuminate\Http\RedirectResponse |
|
* @throws \Illuminate\Validation\ValidationException |
|
*/ |
|
public function __invoke(Podcast $podcast, Request $request) |
|
{ |
|
$this->checkThrottling($request); |
|
|
|
$request->validate([ |
|
'email' => 'required|email', |
|
]); |
|
|
|
Notification::route('mail', $request->only('email')) |
|
->notify(new EmailShareNotification($request->user(), $podcast)); |
|
|
|
$this->incrementAttempts($request); |
|
|
|
session()->flash('alert', trans('podcast.shared_email')); |
|
|
|
return redirect()->back(); |
|
} |
|
} |