Skip to content

Instantly share code, notes, and snippets.

@DarkGhostHunter
Last active October 20, 2019 05:23
Show Gist options
  • Save DarkGhostHunter/b7315b7099927e7ba0854974c7b5c7d7 to your computer and use it in GitHub Desktop.
Save DarkGhostHunter/b7315b7099927e7ba0854974c7b5c7d7 to your computer and use it in GitHub Desktop.
A given controller
<?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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment