NathanGeerinck /
laravel-newsletter
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace App\Http\Controllers; |
||||
| 4 | |||||
| 5 | use App\Models\MailingList; |
||||
| 6 | use App\Models\Subscription; |
||||
| 7 | use App\Http\Requests\SubscribeRequest; |
||||
| 8 | |||||
| 9 | class SubscribeController extends Controller |
||||
| 10 | { |
||||
| 11 | /** |
||||
| 12 | * @param MailingList $list |
||||
| 13 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||||
| 14 | */ |
||||
| 15 | public function mailing_list(MailingList $list) |
||||
| 16 | { |
||||
| 17 | abort_unless($list->public, 404); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 18 | |||||
| 19 | return view('subscribe.list', compact('list')); |
||||
| 20 | } |
||||
| 21 | |||||
| 22 | /** |
||||
| 23 | * @param SubscribeRequest $request |
||||
| 24 | * @param MailingList $list |
||||
| 25 | * @return \Illuminate\Http\RedirectResponse |
||||
| 26 | */ |
||||
| 27 | public function subscribe(SubscribeRequest $request, MailingList $list) |
||||
| 28 | { |
||||
| 29 | $subscription = $list->subscriptions()->create($request->all()); |
||||
|
0 ignored issues
–
show
|
|||||
| 30 | |||||
| 31 | notify()->flash($list->name, 'success', [ |
||||
| 32 | 'timer' => 2000, |
||||
| 33 | 'text' => trans('subscriptions.subscribe.success'), |
||||
| 34 | ]); |
||||
| 35 | |||||
| 36 | return redirect()->back(); |
||||
| 37 | } |
||||
| 38 | |||||
| 39 | /** |
||||
| 40 | * @param $email |
||||
| 41 | * @param $unSubscribe |
||||
| 42 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||||
| 43 | */ |
||||
| 44 | public function preUnSubscribe($email, $unSubscribe) |
||||
| 45 | { |
||||
| 46 | $subscription = Subscription::whereEmail($email)->whereUnsubscribe($unSubscribe)->first(); |
||||
| 47 | |||||
| 48 | abort_unless($subscription, 404); |
||||
|
0 ignored issues
–
show
It seems like
$subscription can also be of type App\Models\Subscription; however, parameter $boolean of abort_unless() does only seem to accept boolean, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 49 | |||||
| 50 | return view('subscriptions.unsubscribe', compact('subscription')); |
||||
| 51 | } |
||||
| 52 | |||||
| 53 | /** |
||||
| 54 | * @param Subscription $subscription |
||||
| 55 | * @return \Illuminate\Http\RedirectResponse |
||||
| 56 | */ |
||||
| 57 | public function unSubscribe(Subscription $subscription) |
||||
| 58 | { |
||||
| 59 | $subscription->delete(); |
||||
| 60 | |||||
| 61 | notify()->flash(trans('general.woohoo'), 'success', [ |
||||
|
0 ignored issues
–
show
It seems like
trans('general.woohoo') can also be of type array; however, parameter $message of Codecourse\Notify\Notifier::flash() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 62 | 'timer' => 3500, |
||||
| 63 | 'text' => trans('subscriptions.unsubscribe.success'), |
||||
| 64 | ]); |
||||
| 65 | |||||
| 66 | return redirect()->route('index'); |
||||
| 67 | } |
||||
| 68 | } |
||||
| 69 |