diff --git a/.gitignore b/.gitignore index d54b1c530..b2d4f5df4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.log /.phpunit.cache /node_modules /public/build diff --git a/app/Console/Commands/ConfirmationEmails.php b/app/Console/Commands/ConfirmationEmails.php index a16c6a65c..875b73428 100644 --- a/app/Console/Commands/ConfirmationEmails.php +++ b/app/Console/Commands/ConfirmationEmails.php @@ -4,27 +4,17 @@ use App\Mail\RetreatConfirmation; use Carbon\Carbon; +use Illuminate\Console\Attributes\Description; +use Illuminate\Console\Attributes\Signature; use Illuminate\Console\Command; use Illuminate\Mail\Mailer; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; +#[Signature('email:confirmations')] +#[Description('Send out confirmation emails one week prior to start date for Ignatian retreats')] class ConfirmationEmails extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ - protected $signature = 'email:confirmations'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Send out confirmation emails one week prior to start date for Ignatian retreats'; - protected $mailer; /** diff --git a/app/Console/Commands/GetMailgunMessages.php b/app/Console/Commands/GetMailgunMessages.php index 8e09a7b34..71a0e5a14 100644 --- a/app/Console/Commands/GetMailgunMessages.php +++ b/app/Console/Commands/GetMailgunMessages.php @@ -13,29 +13,19 @@ use App\Models\Touchpoint; use App\Traits\MailgunTrait; use Carbon\Carbon; +use Illuminate\Console\Attributes\Description; +use Illuminate\Console\Attributes\Signature; use Illuminate\Console\Command; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Mail; use Mailgun\Mailgun; +#[Signature('mailgun:get')] +#[Description('Retrieve stored events (messages) from Mailgun')] class GetMailgunMessages extends Command { use MailgunTrait; - /** - * The name and signature of the console command. - * - * @var string - */ - protected $signature = 'mailgun:get'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Retrieve stored events (messages) from Mailgun'; - /** * Receive a full_address string from Squarespace and attempt to parse it. * Should return an address array with keys for street, supplemental, city, state, zip, and country @@ -161,14 +151,14 @@ public function handle(): int } */ $messages = Message::whereIsProcessed(0)->get(); - + // dd($messages); foreach ($messages as $message) { // #TOUCHPOINT - if this is a touchpoint // if we have from and to ids for contacts go ahead and create a touchpoint // TODO: validate that from is from enforced domain (if applicable) - $clean_message = str_replace("\r\n", "\n", html_entity_decode(strip_tags($message->body))); - + $clean_message = str_replace("\r\n", "\n", html_entity_decode(strip_tags($message->body))); + if (($message->from_id > 0) && ($message->to_id > 0) && (str_contains($message->recipients, 'touchpoint'))) { try { $touch = new Touchpoint; @@ -310,8 +300,8 @@ function ($m) { // #ORDER - if this is an order for a retreat if (str_contains($message->recipients, 'order')) { - // #Order for SQ5937036 - - if (str_contains($clean_message,'SQ5937036')) { + // #Order for SQ5937036 - + if (str_contains($clean_message, 'SQ5937036')) { $order_number = $this->extract_value_between($clean_message, 'Order #', '.'); $order_date = $this->extract_value_between($clean_message, 'Placed on', 'CT.'); $message_info = $this->extract_value_between($clean_message, 'BILLED TO:', 'Item Subtotal'); @@ -327,23 +317,22 @@ function ($m) { // rekey the array $retreat = array_values($retreat); - $order = SquarespaceOrder::firstOrCreate([ 'order_number' => $order_number, ]); $order->message_id = $message->id; $order->created_at = (isset($order_date)) ? Carbon::parse($order_date) : Carbon::now(); - $order->retreat_category = "Workshop"; - $order->retreat_sku = "SQ5937036"; - $order->retreat_description="Prayer and Discernment Workshop"; - $order->retreat_dates="March 22, 2026 - November 8, 2026"; + $order->retreat_category = 'Workshop'; + $order->retreat_sku = 'SQ5937036'; + $order->retreat_description = 'Prayer and Discernment Workshop'; + $order->retreat_dates = 'March 22, 2026 - November 8, 2026'; // $order->event_id = 6334; //prod $order->event_id = 520; // dev - - $order->retreat_start_date = Carbon::parse("2026-03-22"); - $order->retreat_idnumber = "20260322-W"; - $order->retreat_registration_type = "Registration and Payment in Full"; + + $order->retreat_start_date = Carbon::parse('2026-03-22'); + $order->retreat_idnumber = '20260322-W'; + $order->retreat_registration_type = 'Registration and Payment in Full'; $order->retreat_quantity = 1; $order->deposit_amount = 115; $order->unit_price = 115; @@ -351,318 +340,313 @@ function ($m) { $stripe_url = $this->extract_stripe_url($message->body); if (isset($stripe_url) && strpos($stripe_url, 'http') === 0) { - $result = Http::timeout(2)->get($stripe_url)->getBody()->getContents(); - $charge = trim($this->extract_value($result, 'redirect=%2Fpayments%2F')); - $stripe_charge = str_replace('">', '', $charge); - $order->stripe_charge_id = (isset($stripe_charge)) ? $stripe_charge : null; + $result = Http::timeout(2)->get($stripe_url)->getBody()->getContents(); + $charge = trim($this->extract_value($result, 'redirect=%2Fpayments%2F')); + $stripe_charge = str_replace('">', '', $charge); + $order->stripe_charge_id = (isset($stripe_charge)) ? $stripe_charge : null; } - + $order->save(); // dd($order, $order_number,$order_date, $message->id, $retreat, $message_info, $clean_message); - - - - - } else { - try { - if (strpos($clean_message, 'Form Submission - Gift Certificate Registration') > 0) { - // gift certificate registration - - $message_info = $this->extract_value_between($clean_message, 'Form Submission - Gift Certificate Registration', 'Does this submission look like spam?'); - - $retreat = array_values(array_filter(explode("\n", $message_info))); - $retreat = array_map('trim', $retreat); - // remove blank lines - $retreat = array_filter($retreat); - // remove line with only a space in it that was not removed from the trim above, grrr - $retreat = array_filter($retreat, function ($value) { - return $value !== "\xC2\xA0"; - }); - // rekey the array - $retreat = array_values($retreat); - - $custom_form = SquarespaceCustomForm::whereName('Gift Certificate Registration')->firstOrFail(); - $fields = SquarespaceCustomFormField::whereFormId($custom_form->id)->orderBy('sort_order')->get(); - - $order = SquarespaceOrder::whereMessageId($message->id)->firstOrNew(['message_id' => $message->id]); - // dd($clean_message, $retreat, $custom_form, $fields); - - // parse Squarespace Custom Fields and add data to $order - $names = $fields->pluck('name')->toArray(); - foreach ($fields as $field) { - $extracted_value = $this->extract_data($retreat, $field->name.':'); - $order->{$field->variable_name} = $extracted_value; - // to remove empty values where the extracted value is actually the name of the next field - // ideally I would think this would be done by extract_value but that would require passing $names to it each time - $field->search = array_search(str_replace(':', '', $extracted_value), $names); - if ($field->search) { - $order->{$field->variable_name} = null; - } - } + try { + if (strpos($clean_message, 'Form Submission - Gift Certificate Registration') > 0) { + // gift certificate registration - $order->date_of_birth = ($order->date_of_birth == 1) ? null : $order->date_of_birth; - $order->date_of_birth = (isset($order->date_of_birth)) ? \Carbon\Carbon::parse($order->date_of_birth) : null; - $order->comments = (str_contains($order->comments, 'Sent via form submission')) ? null : $order->comments; - - // TODO: DRY - refactor into a process_order_full_address method - if (isset($order->full_address)) { - $address = explode(', ', $order->full_address); - - if (count($address) == 4) { - $order->address_street = trim($address[0]); - // $order->address_supplemental = trim($address[1]); - $order->address_city = trim($address[1]); - $address_detail = explode(' ', $address[2]); - $order->address_state = trim($address_detail[0]); - $order->address_zip = trim($address_detail[1]); - $order->address_country = 'United States'; - // $order->address_country = (count($address_detail) == 4) ? trim($address_detail[2]).' '.trim($address_detail[3]) : trim($address_detail[2]); - } + $message_info = $this->extract_value_between($clean_message, 'Form Submission - Gift Certificate Registration', 'Does this submission look like spam?'); - if (count($address) == 3) { - $order->address_street = trim($address[0]); - $order->address_city = trim($address[1]); - $address_detail = explode(' ', $address[2]); + $retreat = array_values(array_filter(explode("\n", $message_info))); + $retreat = array_map('trim', $retreat); + // remove blank lines + $retreat = array_filter($retreat); + // remove line with only a space in it that was not removed from the trim above, grrr + $retreat = array_filter($retreat, function ($value) { + return $value !== "\xC2\xA0"; + }); + // rekey the array + $retreat = array_values($retreat); + + $custom_form = SquarespaceCustomForm::whereName('Gift Certificate Registration')->firstOrFail(); + $fields = SquarespaceCustomFormField::whereFormId($custom_form->id)->orderBy('sort_order')->get(); + + $order = SquarespaceOrder::whereMessageId($message->id)->firstOrNew(['message_id' => $message->id]); + // dd($clean_message, $retreat, $custom_form, $fields); + + // parse Squarespace Custom Fields and add data to $order + $names = $fields->pluck('name')->toArray(); + foreach ($fields as $field) { + $extracted_value = $this->extract_data($retreat, $field->name.':'); + $order->{$field->variable_name} = $extracted_value; + // to remove empty values where the extracted value is actually the name of the next field + // ideally I would think this would be done by extract_value but that would require passing $names to it each time + $field->search = array_search(str_replace(':', '', $extracted_value), $names); + if ($field->search) { + $order->{$field->variable_name} = null; + } } - if (isset($address_detail)) { - $order->address_state = trim($address_detail[0]); - $order->address_zip = trim($address_detail[1]); - - if (count($address_detail) == 3) { - $order->address_country = trim($address_detail[2]); + $order->date_of_birth = ($order->date_of_birth == 1) ? null : $order->date_of_birth; + $order->date_of_birth = (isset($order->date_of_birth)) ? \Carbon\Carbon::parse($order->date_of_birth) : null; + $order->comments = (str_contains($order->comments, 'Sent via form submission')) ? null : $order->comments; + + // TODO: DRY - refactor into a process_order_full_address method + if (isset($order->full_address)) { + $address = explode(', ', $order->full_address); + + if (count($address) == 4) { + $order->address_street = trim($address[0]); + // $order->address_supplemental = trim($address[1]); + $order->address_city = trim($address[1]); + $address_detail = explode(' ', $address[2]); + $order->address_state = trim($address_detail[0]); + $order->address_zip = trim($address_detail[1]); + $order->address_country = 'United States'; + // $order->address_country = (count($address_detail) == 4) ? trim($address_detail[2]).' '.trim($address_detail[3]) : trim($address_detail[2]); } - if (count($address_detail) == 4) { - $order->address_country = trim($address_detail[2]).' '.trim($address_detail[3]); + if (count($address) == 3) { + $order->address_street = trim($address[0]); + $order->address_city = trim($address[1]); + $address_detail = explode(' ', $address[2]); } - } - } else { - // something is wrong with the address - leave it as null - } - $retreat_number = substr($order->retreat_description, - strpos($order->retreat_description, '#') + 1, - (strpos($order->retreat_description, ' ') - strpos($order->retreat_description, '#')) - ); - $retreat_year = substr($order->retreat_description, strpos($order->retreat_description, ')') - 4, 4); - $retreat_idnumber = trim(strval($retreat_year).$retreat_number); - $order->retreat_idnumber = $retreat_idnumber; - $event = Retreat::whereIdnumber($retreat_idnumber)->first(); - - $order->retreat_dates = substr($order->retreat_description, strpos($order->retreat_description, '(') + 1, strpos($order->retreat_description, ')') - (strpos($order->retreat_description, '(') + 1)); - $order->message_id = $message->id; - $order->retreat_start_date = $event?->start_date; - $order->retreat_registration_type = 'Gift Certificate Registration'; - $order->event_id = $event?->id; - $order->save(); - } else { - $order_number = $this->extract_value_between($clean_message, 'Order #', '.'); - $order_date = $this->extract_value_between($clean_message, 'Placed on', 'CT. View in Stripe'); - - $order = SquarespaceOrder::firstOrCreate([ - 'order_number' => $order_number, - ]); - - $order->order_number = $order_number; - $order->message_id = $message->id; - $order->created_at = (isset($order_date)) ? Carbon::parse($order_date) : Carbon::now(); - - $message_info = $this->extract_value_between($clean_message, 'SUBTOTAL', 'Item Subtotal'); - - $retreat = array_values(array_filter(explode("\n", $message_info))); - $retreat = array_map('trim', $retreat); - // remove blank lines - $retreat = array_filter($retreat); - // remove line with only a space in it that was not removed from the trim above, grrr - $retreat = array_filter($retreat, function ($value) { - return $value !== "\xC2\xA0"; - }); - // rekey the array - $retreat = array_values($retreat); - - $order->retreat_category = (array_key_exists(0, $retreat)) ? $retreat[0] : null; - - // TODO:: in order for test to pass, we need to have better/more functional seed and factory generated data - $inventory = SquarespaceInventory::whereName($order->retreat_category)->first(); - $custom_form = SquarespaceCustomForm::findOrFail($inventory->custom_form_id); - $fields = SquarespaceCustomFormField::whereFormId($custom_form->id)->orderBy('sort_order')->get(); - - // parse Squarespace Custom Fields and add data to $order - $names = $fields->pluck('name')->toArray(); - foreach ($fields as $field) { - $extracted_value = $this->extract_data($retreat, $field->name.':'); - $order->{$field->variable_name} = $extracted_value; - // to remove empty values where the extracted value is actually the name of the next field - // ideally I would think this would be done by extract_value but that would require passing $names to it each time - $field->search = array_search(str_replace(':', '', $extracted_value), $names); - if ($field->search) { - $order->{$field->variable_name} = null; - } - } - if ($order->retreat_category == 'Retreat Gift Certificate') { // Gift Certificates are Orders - // to use existing order couple_fields for the gift certificate recipient data mark the order as that of a couple - $order->retreat_couple = 'Couple'; - $order->retreat_quantity = $retreat[count($retreat) - 3]; - $order->unit_price = str_replace('$', '', end($retreat)); - $order->save(); + if (isset($address_detail)) { + $order->address_state = trim($address_detail[0]); + $order->address_zip = trim($address_detail[1]); - // TODO: create gift certificate on processing order (not here but in edit after selecting or creating contacts) - } else { // Retreat Registration Order - $order->retreat_sku = (array_key_exists(1, $retreat)) ? $retreat[1] : null; + if (count($address_detail) == 3) { + $order->address_country = trim($address_detail[2]); + } - $first_field_position = array_search($fields[0]->name.':', $retreat); - $product_variation = ''; - for ($i = 2; $i <= $first_field_position - 1; $i++) { - $product_variation = $product_variation.$retreat[$i].' '; + if (count($address_detail) == 4) { + $order->address_country = trim($address_detail[2]).' '.trim($address_detail[3]); + } + } + } else { + // something is wrong with the address - leave it as null } - - $order->retreat_description = trim(substr($product_variation, 0, strpos($product_variation, '('))); - $order->retreat_dates = substr($product_variation, strpos($product_variation, '(') + 1, strpos($product_variation, ')') - (strpos($product_variation, '(') + 1)); - - // TODO: rather than trying to determine if the date in the message are in English or Spanish - // get the year, retreat number and create the idnumber, lookup the event, and get the retreat start date from the actual event - $year = substr($order->retreat_dates, strpos($order->retreat_dates, ', ') + 2); - $retreat_number = substr($order->retreat_description, strpos($order->retreat_description, '#') + 1, (strpos($order->retreat_description, ' ') - strpos($order->retreat_description, '#')) ); + $retreat_year = substr($order->retreat_description, strpos($order->retreat_description, ')') - 4, 4); + $retreat_idnumber = trim(strval($retreat_year).$retreat_number); + $order->retreat_idnumber = $retreat_idnumber; + $event = Retreat::whereIdnumber($retreat_idnumber)->first(); - $idnumber = trim(strval($year).$retreat_number); - $order->retreat_idnumber = $idnumber; - $event = Retreat::whereIdnumber($idnumber)->first(); - + $order->retreat_dates = substr($order->retreat_description, strpos($order->retreat_description, '(') + 1, strpos($order->retreat_description, ')') - (strpos($order->retreat_description, '(') + 1)); + $order->message_id = $message->id; $order->retreat_start_date = $event?->start_date; + $order->retreat_registration_type = 'Gift Certificate Registration'; $order->event_id = $event?->id; + $order->save(); + } else { + $order_number = $this->extract_value_between($clean_message, 'Order #', '.'); + $order_date = $this->extract_value_between($clean_message, 'Placed on', 'CT. View in Stripe'); + + $order = SquarespaceOrder::firstOrCreate([ + 'order_number' => $order_number, + ]); - // $order->deposit_amount = str_replace("$","",$this->extract_value_between($message->body, "\nTOTAL", "$0.00")); - // a bit hacky but TOTAL was being flakey possibly because of SUBTOTAL so Tax was more unique - $deposit_amount = str_replace('$', '', trim(str_replace('TOTAL', '', $this->extract_value_between($clean_message, "Tax\n", '$0.00')))); - $deposit_amount = array_values(array_filter(explode("\n", $deposit_amount))); - $deposit_amount = array_map('trim', $deposit_amount); + $order->order_number = $order_number; + $order->message_id = $message->id; + $order->created_at = (isset($order_date)) ? Carbon::parse($order_date) : Carbon::now(); + + $message_info = $this->extract_value_between($clean_message, 'SUBTOTAL', 'Item Subtotal'); + + $retreat = array_values(array_filter(explode("\n", $message_info))); + $retreat = array_map('trim', $retreat); // remove blank lines - $deposit_amount = array_filter($deposit_amount); + $retreat = array_filter($retreat); // remove line with only a space in it that was not removed from the trim above, grrr - $deposit_amount = array_filter($deposit_amount, function ($value) { + $retreat = array_filter($retreat, function ($value) { return $value !== "\xC2\xA0"; }); // rekey the array - $deposit_amount = array_values($deposit_amount); - $order->deposit_amount = $deposit_amount[0]; - $quantity = $retreat[count($retreat) - 3]; - $unit_price = str_replace('$', '', $retreat[count($retreat) - 2]); - $order->retreat_quantity = isset($quantity) ? $quantity : 0; - $order->unit_price = isset($unit_price) ? $unit_price : 0; - - $registration_type = explode(' / ', $product_variation); - if (isset($registration_type[1])) { - $order->retreat_registration_type = trim($registration_type[1]); + $retreat = array_values($retreat); + + $order->retreat_category = (array_key_exists(0, $retreat)) ? $retreat[0] : null; + + // TODO:: in order for test to pass, we need to have better/more functional seed and factory generated data + $inventory = SquarespaceInventory::whereName($order->retreat_category)->first(); + $custom_form = SquarespaceCustomForm::findOrFail($inventory->custom_form_id); + $fields = SquarespaceCustomFormField::whereFormId($custom_form->id)->orderBy('sort_order')->get(); + + // parse Squarespace Custom Fields and add data to $order + $names = $fields->pluck('name')->toArray(); + foreach ($fields as $field) { + $extracted_value = $this->extract_data($retreat, $field->name.':'); + $order->{$field->variable_name} = $extracted_value; + // to remove empty values where the extracted value is actually the name of the next field + // ideally I would think this would be done by extract_value but that would require passing $names to it each time + $field->search = array_search(str_replace(':', '', $extracted_value), $names); + if ($field->search) { + $order->{$field->variable_name} = null; + } } - switch ($order->retreat_category) { - case 'Open Retreat (Men, Women, and Couples)': - $order->retreat_couple = trim($registration_type[2]); - break; - case 'Retiro en Español': - $order->retreat_couple = trim($registration_type[2]); - break; - case "Couple's Retreat": - $order->retreat_couple = 'Couple'; - break; - case 'Special Event - Man In The Ditch': - $idnumber = '20220618'; - $order->retreat_idnumber = '20220618'; // hardcoded - $order->retreat_dates = 'June 18, 2022'; - $event = Retreat::whereIdnumber($idnumber)->first(); - $order->retreat_start_date = $event?->start_date; - $order->event_id = $event?->id; - $order->retreat_registration_type = 'Registration and Deposit'; - $order->retreat_description = $order->retreat_category; - break; - default: // "Women's Retreat", "Men's Retreat", "Young Adult's Retreat" - break; - } - $order->save(); - // tidy up some of the data - $order->comments = ($order->comments == 1) ? null : $order->comments; - $order->couple_mobile_phone = ($order->couple_mobile_phone == 1) ? null : $order->couple_mobile_phone; - // presumes the field following the couple date of date of birth is the retreat quantity because it is the last field - $order->date_of_birth = ($order->date_of_birth == 1) ? null : $order->date_of_birth; - $order->date_of_birth = (isset($order->date_of_birth)) ? \Carbon\Carbon::parse($order->date_of_birth) : null; - if ($order->is_couple) { - $order->couple_date_of_birth = ($order->couple_date_of_birth == $order->retreat_quantity) ? null : $order->couple_date_of_birth; - $order->couple_date_of_birth = (isset($order->couple_date_of_birth)) ? \Carbon\Carbon::parse($order->couple_date_of_birth) : null; - } - } // Retreat Registration Order - - // attempt to get Stripe charge id for both gift certificates and regular orders - $result = null; - $stripe_charge = null; - // $stripe_url = trim($this->extract_value(str_replace("\r\n","\n", $message->body),"View in Stripe\n"), "<>"); - $stripe_url = $this->extract_stripe_url($message->body); - if (isset($stripe_url) && strpos($stripe_url, 'http') === 0) { - $result = Http::timeout(2)->get($stripe_url)->getBody()->getContents(); - $charge = trim($this->extract_value($result, 'redirect=%2Fpayments%2F')); - $stripe_charge = str_replace('">', '', $charge); - $order->stripe_charge_id = (isset($stripe_charge)) ? $stripe_charge : null; - } + if ($order->retreat_category == 'Retreat Gift Certificate') { // Gift Certificates are Orders + // to use existing order couple_fields for the gift certificate recipient data mark the order as that of a couple + $order->retreat_couple = 'Couple'; + $order->retreat_quantity = $retreat[count($retreat) - 3]; + $order->unit_price = str_replace('$', '', end($retreat)); + $order->save(); + + // TODO: create gift certificate on processing order (not here but in edit after selecting or creating contacts) + } else { // Retreat Registration Order + $order->retreat_sku = (array_key_exists(1, $retreat)) ? $retreat[1] : null; + + $first_field_position = array_search($fields[0]->name.':', $retreat); + $product_variation = ''; + for ($i = 2; $i <= $first_field_position - 1; $i++) { + $product_variation = $product_variation.$retreat[$i].' '; + } - // process order address - // TODO: make sure full_address variable exists otherwise set order address parts to null - // TODO: get the billing address and compare to address provided, different billing address may indicate someone else is paying for the retreat - // TODO: consider comparing extract_value and extract_value_between to better deal with multiple line addresses - if (isset($order->full_address)) { - $address = explode(', ', $order->full_address); - - if (count($address) == 4) { - $order->address_street = trim($address[0]); - $order->address_supplemental = trim($address[1]); - $order->address_city = trim($address[2]); - $address_detail = explode(' ', $address[3]); - $order->address_state = trim($address_detail[0]); - $order->address_zip = trim($address_detail[1]); - $order->address_country = (count($address_detail) == 4) ? trim($address_detail[2]).' '.trim($address_detail[3]) : trim($address_detail[2]); - } + $order->retreat_description = trim(substr($product_variation, 0, strpos($product_variation, '('))); + $order->retreat_dates = substr($product_variation, strpos($product_variation, '(') + 1, strpos($product_variation, ')') - (strpos($product_variation, '(') + 1)); + + // TODO: rather than trying to determine if the date in the message are in English or Spanish + // get the year, retreat number and create the idnumber, lookup the event, and get the retreat start date from the actual event + $year = substr($order->retreat_dates, strpos($order->retreat_dates, ', ') + 2); + + $retreat_number = substr($order->retreat_description, + strpos($order->retreat_description, '#') + 1, + (strpos($order->retreat_description, ' ') - strpos($order->retreat_description, '#')) + ); + + $idnumber = trim(strval($year).$retreat_number); + $order->retreat_idnumber = $idnumber; + $event = Retreat::whereIdnumber($idnumber)->first(); + + $order->retreat_start_date = $event?->start_date; + $order->event_id = $event?->id; + + // $order->deposit_amount = str_replace("$","",$this->extract_value_between($message->body, "\nTOTAL", "$0.00")); + // a bit hacky but TOTAL was being flakey possibly because of SUBTOTAL so Tax was more unique + $deposit_amount = str_replace('$', '', trim(str_replace('TOTAL', '', $this->extract_value_between($clean_message, "Tax\n", '$0.00')))); + $deposit_amount = array_values(array_filter(explode("\n", $deposit_amount))); + $deposit_amount = array_map('trim', $deposit_amount); + // remove blank lines + $deposit_amount = array_filter($deposit_amount); + // remove line with only a space in it that was not removed from the trim above, grrr + $deposit_amount = array_filter($deposit_amount, function ($value) { + return $value !== "\xC2\xA0"; + }); + // rekey the array + $deposit_amount = array_values($deposit_amount); + $order->deposit_amount = $deposit_amount[0]; + $quantity = $retreat[count($retreat) - 3]; + $unit_price = str_replace('$', '', $retreat[count($retreat) - 2]); + $order->retreat_quantity = isset($quantity) ? $quantity : 0; + $order->unit_price = isset($unit_price) ? $unit_price : 0; + + $registration_type = explode(' / ', $product_variation); + if (isset($registration_type[1])) { + $order->retreat_registration_type = trim($registration_type[1]); + } - if (count($address) == 3) { - $order->address_street = trim($address[0]); - $order->address_city = trim($address[1]); - $address_detail = explode(' ', $address[2]); + switch ($order->retreat_category) { + case 'Open Retreat (Men, Women, and Couples)': + $order->retreat_couple = trim($registration_type[2]); + break; + case 'Retiro en Español': + $order->retreat_couple = trim($registration_type[2]); + break; + case "Couple's Retreat": + $order->retreat_couple = 'Couple'; + break; + case 'Special Event - Man In The Ditch': + $idnumber = '20220618'; + $order->retreat_idnumber = '20220618'; // hardcoded + $order->retreat_dates = 'June 18, 2022'; + $event = Retreat::whereIdnumber($idnumber)->first(); + $order->retreat_start_date = $event?->start_date; + $order->event_id = $event?->id; + $order->retreat_registration_type = 'Registration and Deposit'; + $order->retreat_description = $order->retreat_category; + break; + default: // "Women's Retreat", "Men's Retreat", "Young Adult's Retreat" + break; + } + $order->save(); + // tidy up some of the data + $order->comments = ($order->comments == 1) ? null : $order->comments; + $order->couple_mobile_phone = ($order->couple_mobile_phone == 1) ? null : $order->couple_mobile_phone; + // presumes the field following the couple date of date of birth is the retreat quantity because it is the last field + $order->date_of_birth = ($order->date_of_birth == 1) ? null : $order->date_of_birth; + $order->date_of_birth = (isset($order->date_of_birth)) ? \Carbon\Carbon::parse($order->date_of_birth) : null; + if ($order->is_couple) { + $order->couple_date_of_birth = ($order->couple_date_of_birth == $order->retreat_quantity) ? null : $order->couple_date_of_birth; + $order->couple_date_of_birth = (isset($order->couple_date_of_birth)) ? \Carbon\Carbon::parse($order->couple_date_of_birth) : null; + } + } // Retreat Registration Order + + // attempt to get Stripe charge id for both gift certificates and regular orders + $result = null; + $stripe_charge = null; + // $stripe_url = trim($this->extract_value(str_replace("\r\n","\n", $message->body),"View in Stripe\n"), "<>"); + $stripe_url = $this->extract_stripe_url($message->body); + if (isset($stripe_url) && strpos($stripe_url, 'http') === 0) { + $result = Http::timeout(2)->get($stripe_url)->getBody()->getContents(); + $charge = trim($this->extract_value($result, 'redirect=%2Fpayments%2F')); + $stripe_charge = str_replace('">', '', $charge); + $order->stripe_charge_id = (isset($stripe_charge)) ? $stripe_charge : null; } - if (isset($address_detail)) { - $order->address_state = trim($address_detail[0]); - $order->address_zip = trim($address_detail[1]); + // process order address + // TODO: make sure full_address variable exists otherwise set order address parts to null + // TODO: get the billing address and compare to address provided, different billing address may indicate someone else is paying for the retreat + // TODO: consider comparing extract_value and extract_value_between to better deal with multiple line addresses + if (isset($order->full_address)) { + $address = explode(', ', $order->full_address); + + if (count($address) == 4) { + $order->address_street = trim($address[0]); + $order->address_supplemental = trim($address[1]); + $order->address_city = trim($address[2]); + $address_detail = explode(' ', $address[3]); + $order->address_state = trim($address_detail[0]); + $order->address_zip = trim($address_detail[1]); + $order->address_country = (count($address_detail) == 4) ? trim($address_detail[2]).' '.trim($address_detail[3]) : trim($address_detail[2]); + } - if (count($address_detail) == 3) { - $order->address_country = trim($address_detail[2]); + if (count($address) == 3) { + $order->address_street = trim($address[0]); + $order->address_city = trim($address[1]); + $address_detail = explode(' ', $address[2]); } - if (count($address_detail) == 4) { - $order->address_country = trim($address_detail[2]).' '.trim($address_detail[3]); + if (isset($address_detail)) { + $order->address_state = trim($address_detail[0]); + $order->address_zip = trim($address_detail[1]); + + if (count($address_detail) == 3) { + $order->address_country = trim($address_detail[2]); + } + + if (count($address_detail) == 4) { + $order->address_country = trim($address_detail[2]).' '.trim($address_detail[3]); + } } + } else { + // something is wrong with the address - leave it as null } - } else { - // something is wrong with the address - leave it as null - } - $order->save(); + $order->save(); + } + } catch (\Exception $exception) { + // TODO: while debugging - could check for production or developement and turn on or off accordingly to only attempt to send email when in production + // dd($exception, $order, $clean_message, $message->body, $retreat); + + $subject .= ': Creating Squarespace Order for Message Id #'.$message->id; + Mail::send('emails.en_US.error', ['error' => $exception, 'url' => $fullurl, 'user' => $username, 'ip' => $ip_address, 'subject' => $subject], + function ($m) { + $m->to(config('polanco.admin_email')) + ->subject('Error Retrieving Mailgun Messages'); + }); } - } catch (\Exception $exception) { - // TODO: while debugging - could check for production or developement and turn on or off accordingly to only attempt to send email when in production - // dd($exception, $order, $clean_message, $message->body, $retreat); - - $subject .= ': Creating Squarespace Order for Message Id #'.$message->id; - Mail::send('emails.en_US.error', ['error' => $exception, 'url' => $fullurl, 'user' => $username, 'ip' => $ip_address, 'subject' => $subject], - function ($m) { - $m->to(config('polanco.admin_email')) - ->subject('Error Retrieving Mailgun Messages'); - }); - } } } diff --git a/app/Console/Commands/ImportStripePayouts.php b/app/Console/Commands/ImportStripePayouts.php index e6c6ba243..69fbe6e31 100644 --- a/app/Console/Commands/ImportStripePayouts.php +++ b/app/Console/Commands/ImportStripePayouts.php @@ -5,25 +5,15 @@ use App\Models\StripeBalanceTransaction; use App\Models\StripePayout; use Carbon\Carbon; +use Illuminate\Console\Attributes\Description; +use Illuminate\Console\Attributes\Signature; use Illuminate\Console\Command; use Stripe\StripeClient; +#[Signature('import:stripe_payouts')] +#[Description('Import Stripe Payouts')] class ImportStripePayouts extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ - protected $signature = 'import:stripe_payouts'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Import Stripe Payouts'; - /** * Create a new command instance. * diff --git a/app/Console/Commands/PostRetreatEmails.php b/app/Console/Commands/PostRetreatEmails.php index 1f929af67..cc9524d7d 100644 --- a/app/Console/Commands/PostRetreatEmails.php +++ b/app/Console/Commands/PostRetreatEmails.php @@ -5,25 +5,15 @@ use App\Mail\PostRetreat; use App\Models\Retreat; use Carbon\Carbon; +use Illuminate\Console\Attributes\Description; +use Illuminate\Console\Attributes\Signature; use Illuminate\Console\Command; use Illuminate\Support\Facades\Mail; +#[Signature('email:post-retreat')] +#[Description('Send out post retreat emails.')] class PostRetreatEmails extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ - protected $signature = 'email:post-retreat'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Send out post retreat emails.'; - /** * Create a new command instance. * diff --git a/app/Console/Commands/SendBirthdays.php b/app/Console/Commands/SendBirthdays.php index b693aa9d3..d2e9e179b 100644 --- a/app/Console/Commands/SendBirthdays.php +++ b/app/Console/Commands/SendBirthdays.php @@ -5,26 +5,16 @@ use App\Mail\RetreatantBirthday; use App\Models\Contact; use Carbon\Carbon; +use Illuminate\Console\Attributes\Description; +use Illuminate\Console\Attributes\Signature; use Illuminate\Console\Command; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Storage; +#[Signature('email:birthdays')] +#[Description('Sends out birthday emails to retreatants with birthdays of current day.')] class SendBirthdays extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ - protected $signature = 'email:birthdays'; - - /** - * The console command description. - * - * @var string - */ - protected $description = 'Sends out birthday emails to retreatants with birthdays of current day.'; - /** * Create a new command instance. * diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 3607c7b45..e249941bd 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -6,26 +6,20 @@ use App\Http\Requests\UpdateActivityRequest; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class ActivityController extends Controller implements HasMiddleware +#[Middleware('auth')] +class ActivityController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-activity')] public function index(): View { - Gate::authorize('show-activity'); $activities = \App\Models\Activity::orderBy('activity_date_time', 'desc')->paginate(25, ['*'], 'activities'); return view('activities.index', compact('activities')); @@ -34,9 +28,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-activity')] public function create(Request $request): View { - Gate::authorize('create-activity'); $staff = \App\Models\Contact::with('groups')->whereHas('groups', function ($query) { $query->where('group_id', '=', config('polanco.group_id.staff')); })->orderBy('sort_name')->pluck('sort_name', 'id'); @@ -64,9 +58,9 @@ public function create(Request $request): View /** * Store a newly created resource in storage. */ + #[Authorize('create-activity')] public function store(StoreActivityRequest $request): RedirectResponse { - Gate::authorize('create-activity'); $activity_type = \App\Models\ActivityType::findOrFail($request->input('activity_type_id')); $activity = new \App\Models\Activity; $activity->activity_type_id = $request->input('activity_type_id'); @@ -105,9 +99,9 @@ public function store(StoreActivityRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-activity')] public function show(int $id): View { - Gate::authorize('show-activity'); $activity = \App\Models\Activity::with('assignees', 'creators', 'targets')->findOrFail($id); return view('activities.show', compact('activity')); // @@ -116,9 +110,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-activity')] public function edit(int $id): View { - Gate::authorize('update-activity'); $activity = \App\Models\Activity::findOrFail($id); $target = $activity->targets->first(); $assignee = $activity->assignees->first(); @@ -151,9 +145,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-activity')] public function update(UpdateActivityRequest $request, int $id): RedirectResponse { - Gate::authorize('update-activity'); $activity_type = \App\Models\ActivityType::findOrFail($request->input('activity_type_id')); $activity = \App\Models\Activity::findOrFail($id); @@ -187,11 +181,11 @@ public function update(UpdateActivityRequest $request, int $id): RedirectRespons /** * Remove the specified resource from storage. */ + #[Authorize('delete-activity')] public function destroy(int $id): RedirectResponse { // delete activity contacts and then the activity (could be handled in model with cascading deletes) - Gate::authorize('delete-activity'); \App\Models\ActivityContact::whereActivityId($id)->delete(); \App\Models\Activity::destroy($id); diff --git a/app/Http/Controllers/AddressController.php b/app/Http/Controllers/AddressController.php index 60d0b07be..d1074e0fc 100644 --- a/app/Http/Controllers/AddressController.php +++ b/app/Http/Controllers/AddressController.php @@ -6,8 +6,8 @@ use App\Http\Requests\UpdateAddressRequest; use App\Models\Address; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; @@ -16,21 +16,15 @@ * In testing, the address controller uses CRUD-style permissions which are theoretical rather than the contact CRUD permissions used in production * In other words, in production, the create-contact permission is used rather than create-address. */ -class AddressController extends Controller implements HasMiddleware +#[Middleware('auth')] +class AddressController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-address')] public function index(): View { - Gate::authorize('show-address'); $addresses = \App\Models\Address::orderBy('postal_code', 'asc')->with('addressee')->paginate(25, ['*'], 'addresses'); return view('addresses.index', compact('addresses')); @@ -39,9 +33,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-address')] public function create(): View { - Gate::authorize('create-address'); $countries = \App\Models\Country::orderBy('iso_code')->pluck('iso_code', 'id'); $countries->prepend('N/A', ''); $states = \App\Models\StateProvince::orderBy('name')->whereCountryId(config('polanco.country_id_usa'))->pluck('name', 'id'); @@ -55,9 +49,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-address')] public function store(StoreAddressRequest $request): RedirectResponse { - Gate::authorize('create-address'); $address = new \App\Models\Address; $address->contact_id = $request->input('contact_id'); $address->location_type_id = $request->input('location_type_id'); @@ -78,9 +72,9 @@ public function store(StoreAddressRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-address')] public function show(int $id): View { - Gate::authorize('show-address'); $address = \App\Models\Address::with('addressee')->findOrFail($id); return view('addresses.show', compact('address')); @@ -89,10 +83,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-address')] public function edit(int $id): View { - Gate::authorize('update-address'); - $countries = \App\Models\Country::orderBy('iso_code')->pluck('iso_code', 'id'); $countries->prepend('N/A', ''); $states = \App\Models\StateProvince::orderBy('name')->whereCountryId(config('polanco.country_id_usa'))->pluck('name', 'id'); @@ -107,9 +100,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-address')] public function update(UpdateAddressRequest $request, int $id): RedirectResponse { - Gate::authorize('update-address'); $address = \App\Models\Address::findOrFail($id); $address->contact_id = $request->input('contact_id'); $address->location_type_id = $request->input('location_type_id'); @@ -130,9 +123,9 @@ public function update(UpdateAddressRequest $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-address')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-address'); $address = \App\Models\Address::findOrFail($id); $contact_id = $address->contact_id; \App\Models\Address::destroy($id); diff --git a/app/Http/Controllers/AssetController.php b/app/Http/Controllers/AssetController.php index 625dad0be..012ad9d9f 100644 --- a/app/Http/Controllers/AssetController.php +++ b/app/Http/Controllers/AssetController.php @@ -6,24 +6,17 @@ use App\Http\Requests\StoreAssetRequest; use App\Http\Requests\UpdateAssetRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class AssetController extends Controller implements HasMiddleware +#[Middleware('auth')] +class AssetController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-asset')] public function index(): View { - Gate::authorize('show-asset'); - $asset_types = \App\Models\AssetType::active()->orderBy('label')->pluck('label', 'id'); $locations = \App\Models\Location::orderBy('name')->pluck('name', 'id'); @@ -32,10 +25,9 @@ public function index(): View return view('assets.index', compact('assets', 'asset_types', 'locations')); } + #[Authorize('show-asset')] public function index_type($type = null): View { - Gate::authorize('show-asset'); - $asset_types = \App\Models\AssetType::active()->orderBy('label')->pluck('label', 'id'); $locations = \App\Models\Location::orderBy('name')->pluck('name', 'id'); @@ -44,10 +36,9 @@ public function index_type($type = null): View return view('assets.index', compact('assets', 'asset_types', 'locations')); } + #[Authorize('show-asset')] public function index_location($location_id = null): View { - Gate::authorize('show-asset'); - $asset_types = \App\Models\AssetType::active()->orderBy('label')->pluck('label', 'id'); $locations = \App\Models\Location::orderBy('name')->pluck('name', 'id'); @@ -56,10 +47,9 @@ public function index_location($location_id = null): View return view('assets.index', compact('assets', 'asset_types', 'locations')); } + #[Authorize('show-asset')] public function search(): View { - Gate::authorize('show-asset'); - $asset_types = \App\Models\AssetType::active()->orderBy('label')->pluck('label', 'id'); $asset_types->prepend('N/A', ''); @@ -96,9 +86,9 @@ public function search(): View return view('assets.search', compact('asset_types', 'departments', 'depreciation_types', 'locations', 'parents', 'uoms_capacity', 'uoms_electric', 'uoms_length', 'uoms_time', 'uoms_weight', 'vendors')); } + #[Authorize('show-asset')] public function results(AssetSearchRequest $request): View { - Gate::authorize('show-asset'); if (! empty($request)) { $assets = \App\Models\Asset::filtered($request)->orderBy('name')->paginate(25, ['*'], 'assets'); $assets->appends($request->except('page')); @@ -112,10 +102,9 @@ public function results(AssetSearchRequest $request): View /** * Show the form for creating a new resource. */ + #[Authorize('create-asset')] public function create(): View { - Gate::authorize('create-asset'); - $asset_types = \App\Models\AssetType::active()->orderBy('label')->pluck('label', 'id'); $asset_types->prepend('N/A', ''); @@ -150,10 +139,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-asset')] public function store(StoreAssetRequest $request): RedirectResponse { - Gate::authorize('create-asset'); - $asset = new \App\Models\Asset; // General info $asset->name = $request->input('name'); @@ -235,10 +223,9 @@ public function store(StoreAssetRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-asset')] public function show(int $id): View { - Gate::authorize('show-asset'); - $asset = \App\Models\Asset::with('tasks.jobs')->findOrFail($id); $files = \App\Models\Attachment::whereEntity('asset')->whereEntityId($asset->id)->whereFileTypeId(config('polanco.file_type.asset_attachment'))->get(); @@ -248,10 +235,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-asset')] public function edit(int $id): View { - Gate::authorize('update-asset'); - $asset = \App\Models\Asset::findOrFail($id); $asset_types = \App\Models\AssetType::active()->orderBy('label')->pluck('label', 'id'); @@ -288,10 +274,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-asset')] public function update(UpdateAssetRequest $request, int $id): RedirectResponse { - Gate::authorize('update-asset'); - $asset = \App\Models\Asset::findOrFail($id); // General info @@ -380,9 +365,9 @@ public function update(UpdateAssetRequest $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-asset')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-asset'); $asset = \App\Models\Asset::findOrFail($id); \App\Models\Asset::destroy($id); diff --git a/app/Http/Controllers/AssetJobController.php b/app/Http/Controllers/AssetJobController.php index d01dc588b..3ac2e03d8 100644 --- a/app/Http/Controllers/AssetJobController.php +++ b/app/Http/Controllers/AssetJobController.php @@ -5,25 +5,18 @@ use App\Http\Requests\StoreAssetJobRequest; use App\Http\Requests\UpdateAssetJobRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Arr; -use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class AssetJobController extends Controller implements HasMiddleware +#[Middleware('auth')] +class AssetJobController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-asset-job')] public function index(): View { - Gate::authorize('show-asset-job'); - $asset_jobs = \App\Models\AssetJob::with('asset_task.asset', 'assigned_to')->orderBy('scheduled_date')->get(); return view('asset_jobs.index', compact('asset_jobs')); @@ -32,10 +25,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-asset-job')] public function create($asset_task_id = 0): View { - Gate::authorize('create-asset-job'); - // if creating a task for a particular asset (default behavior from asset.show blade) then no need to get long list of assets to choose from if (isset($asset_task_id) && $asset_task_id > 0) { $asset_tasks = \App\Models\AssetTask::whereId($asset_task_id)->pluck('title', 'id'); @@ -58,10 +50,9 @@ public function create($asset_task_id = 0): View /** * Store a newly created resource in storage. */ + #[Authorize('create-asset-job')] public function store(StoreAssetJobRequest $request): RedirectResponse { - Gate::authorize('create-asset-job'); - $asset_job = new \App\Models\AssetJob; // General info @@ -95,10 +86,9 @@ public function store(StoreAssetJobRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-asset-job')] public function show(int $id): View { - Gate::authorize('show-asset-job'); - $asset_job = \App\Models\AssetJob::findOrFail($id); return view('asset_jobs.show', compact('asset_job')); @@ -107,10 +97,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-asset-job')] public function edit(int $id): View { - Gate::authorize('update-asset-job'); - $asset_job = \App\Models\AssetJob::findOrFail($id); $asset_tasks = \App\Models\AssetTask::orderBy('title')->pluck('title', 'id'); @@ -134,10 +123,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-asset-job')] public function update(UpdateAssetJobRequest $request, int $id): RedirectResponse { - Gate::authorize('update-asset-job'); - $asset_job = \App\Models\AssetJob::findOrFail($id); // General info @@ -177,9 +165,9 @@ public function update(UpdateAssetJobRequest $request, int $id): RedirectRespons /** * Remove the specified resource from storage. */ + #[Authorize('delete-asset-job')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-asset-job'); $asset_job = \App\Models\AssetJob::findOrFail($id); \App\Models\AssetJob::destroy($id); diff --git a/app/Http/Controllers/AssetTaskController.php b/app/Http/Controllers/AssetTaskController.php index 801743d26..d515db6f3 100644 --- a/app/Http/Controllers/AssetTaskController.php +++ b/app/Http/Controllers/AssetTaskController.php @@ -5,24 +5,17 @@ use App\Http\Requests\StoreAssetTaskRequest; use App\Http\Requests\UpdateAssetTaskRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class AssetTaskController extends Controller implements HasMiddleware +#[Middleware('auth')] +class AssetTaskController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-asset-task')] public function index(): View { - Gate::authorize('show-asset-task'); - $asset_tasks = \App\Models\AssetTask::with('asset')->orderBy('title')->get(); return view('asset_tasks.index', compact('asset_tasks')); @@ -31,10 +24,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-asset-task')] public function create($asset_id = 0): View { - Gate::authorize('create-asset-task'); - // if creating a task for a particular asset (default behavior from asset.show blade) then no need to get long list of assets to choose from if (isset($asset_id) && $asset_id > 0) { $assets = \App\Models\Asset::whereId($asset_id)->pluck('name', 'id'); @@ -56,10 +48,9 @@ public function create($asset_id = 0): View /** * Store a newly created resource in storage. */ + #[Authorize('create-asset-task')] public function store(StoreAssetTaskRequest $request): RedirectResponse { - Gate::authorize('create-asset-task'); - $asset_task = new \App\Models\AssetTask; $asset_task->asset_id = $request->input('asset_id'); @@ -91,10 +82,9 @@ public function store(StoreAssetTaskRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-asset-task')] public function show(int $id): View { - Gate::authorize('show-asset-task'); - $asset_task = \App\Models\AssetTask::with('jobs')->findOrFail($id); $jobs_scheduled = \App\Models\AssetJob::whereAssetTaskId($id)->where('scheduled_date', '>=', now())->orderBy('scheduled_date')->get(); $jobs_past = \App\Models\AssetJob::whereAssetTaskId($id)->where('scheduled_date', '<', now())->orderBy('scheduled_date')->get(); @@ -105,10 +95,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-asset-task')] public function edit(int $id): View { - Gate::authorize('update-asset-task'); - $asset_task = \App\Models\AssetTask::findOrFail($id); $assets = \App\Models\Asset::orderBy('name')->pluck('name', 'id'); @@ -126,10 +115,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-asset-task')] public function update(UpdateAssetTaskRequest $request, int $id): RedirectResponse { - Gate::authorize('update-asset-task'); - $asset_task = \App\Models\AssetTask::findOrFail($id); $asset_task->asset_id = $request->input('asset_id'); @@ -161,9 +149,9 @@ public function update(UpdateAssetTaskRequest $request, int $id): RedirectRespon /** * Remove the specified resource from storage. */ + #[Authorize('delete-asset-task')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-asset-task'); $asset_task = \App\Models\AssetTask::findOrFail($id); \App\Models\AssetTask::destroy($id); @@ -183,9 +171,9 @@ public function destroy(int $id): RedirectResponse * This approach ensures job history is maintained by not deleting previously scheduled jobs * It also allows for Nonscheduled - not automated PM - to remain as only future, scheduled jobs are deleted */ + #[Authorize('update-asset-task')] public function schedule_jobs(int $id): RedirectResponse { - Gate::authorize('update-asset-task'); $asset_task = \App\Models\AssetTask::findOrFail($id); $jobs_created = 0; diff --git a/app/Http/Controllers/AssetTypeController.php b/app/Http/Controllers/AssetTypeController.php index 3fd546022..e39f32cd3 100644 --- a/app/Http/Controllers/AssetTypeController.php +++ b/app/Http/Controllers/AssetTypeController.php @@ -5,23 +5,17 @@ use App\Http\Requests\StoreAssetTypeRequest; use App\Http\Requests\UpdateAssetTypeRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class AssetTypeController extends Controller implements HasMiddleware +#[Middleware('auth')] +class AssetTypeController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-asset-type')] public function index(): View { - Gate::authorize('show-asset-type'); $asset_types = \App\Models\AssetType::orderBy('label')->get(); return view('admin.asset_types.index', compact('asset_types')); @@ -30,9 +24,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-asset-type')] public function create(): View { - Gate::authorize('create-asset-type'); $asset_types = \App\Models\AssetType::active()->orderBy('label')->pluck('label', 'id'); $asset_types->prepend('N/A', 0); @@ -42,10 +36,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-asset-type')] public function store(StoreAssetTypeRequest $request): RedirectResponse { - Gate::authorize('create-asset-type'); - $asset_type = new \App\Models\AssetType; $asset_type->label = $request->input('label'); $asset_type->name = $request->input('name'); @@ -63,10 +56,9 @@ public function store(StoreAssetTypeRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-asset-type')] public function show(int $id): View { - Gate::authorize('show-asset-type'); - $asset_type = \App\Models\AssetType::findOrFail($id); return view('admin.asset_types.show', compact('asset_type')); @@ -75,10 +67,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-asset-type')] public function edit(int $id): View { - Gate::authorize('update-asset-type'); - $asset_type = \App\Models\AssetType::findOrFail($id); $asset_types = \App\Models\AssetType::active()->orderBy('label')->pluck('label', 'id'); $asset_types->prepend('N/A', 0); @@ -89,10 +80,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-asset-type')] public function update(UpdateAssetTypeRequest $request, int $id): RedirectResponse { - Gate::authorize('update-asset-type'); - $asset_type = \App\Models\AssetType::findOrFail($request->input('id')); $asset_type->name = $request->input('name'); $asset_type->label = $request->input('label'); @@ -109,9 +99,9 @@ public function update(UpdateAssetTypeRequest $request, int $id): RedirectRespon /** * Remove the specified resource from storage. */ + #[Authorize('delete-asset-type')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-asset-type'); $asset_type = \App\Models\AssetType::findOrFail($id); \App\Models\AssetType::destroy($id); diff --git a/app/Http/Controllers/AttachmentController.php b/app/Http/Controllers/AttachmentController.php index 3ac8cfc18..ccec425b7 100644 --- a/app/Http/Controllers/AttachmentController.php +++ b/app/Http/Controllers/AttachmentController.php @@ -6,7 +6,8 @@ use App\Http\Requests\UpdateAttachmentRequest; use Carbon\Carbon; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Redirect; @@ -14,15 +15,9 @@ use Illuminate\View\View; use Intervention\Image\Facades\Image; -class AttachmentController extends Controller implements HasMiddleware +#[Middleware('auth')] +class AttachmentController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - public function sanitize_filename($filename) { $sanitized = preg_replace('/[^a-zA-Z0-9\\-\\._]/', '', $filename); @@ -95,9 +90,9 @@ public function show_attachment($entity, $entity_id, $type = 'attachment', $file return $response; } + #[Authorize('create-attachment')] public function store_attachment($file, $entity = 'event', $entity_id = 0, $type = null, $description = null) { // TODO: Not sure if this is being called from anywhere but contact attachments seems to be missing the attachments folder in the path (see update_attachment method) - Gate::authorize('create-attachment'); $file_name = $this->sanitize_filename($file->getClientOriginalName()); $attachment = new \App\Models\Attachment; $attachment->mime_type = $file->getClientMimeType(); @@ -359,10 +354,9 @@ public function update_attachment($file, $entity = 'event', $entity_id = 0, $typ $attachment->save(); } + #[Authorize('delete-attachment')] public function delete_attachment($file_name, $entity = 'event', $entity_id = 0, $type = null): RedirectResponse { - Gate::authorize('delete-attachment'); - $path = $entity.'/'.$entity_id.'/'; switch ($type) { case 'group_photo': @@ -437,42 +431,39 @@ public function delete_attachment($file_name, $entity = 'event', $entity_id = 0, return Redirect::action([\App\Http\Controllers\RetreatController::class, 'show'], $entity_id); } + #[Authorize('show-attachment')] public function show_contact_attachment($user_id, $file_name) { - Gate::authorize('show-attachment'); - return $this->show_attachment('contact', $user_id, 'attachment', $file_name); } + #[Authorize('show-event-attachment')] public function show_event_attachment($event_id, $file_name) { - Gate::authorize('show-event-attachment'); - return $this->show_attachment('event', $event_id, 'event-attachment', $file_name); } + #[Authorize('delete-attachment')] public function delete_contact_attachment($user_id, $attachment): RedirectResponse { - Gate::authorize('delete-attachment'); $this->delete_attachment($attachment, 'contact', $user_id, 'attachment'); // TODO: get contact type and redirect to person, parish, organization, vendor as appropriate return Redirect::action([\App\Http\Controllers\PersonController::class, 'show'], $user_id); } + #[Authorize('delete-attachment')] public function delete_event_attachment($event_id, $attachment): RedirectResponse { - Gate::authorize('delete-attachment'); // TODO: for testing simplicity I am not implementing the use of delete-event-attachment $this->delete_attachment($attachment, 'event', $event_id, 'event-attachment'); // TODO: get contact type and redirect to person, parish, organization, vendor as appropriate return Redirect::action([\App\Http\Controllers\RetreatController::class, 'show'], $event_id); } + #[Authorize('show-avatar')] public function get_avatar($user_id) { - Gate::authorize('show-avatar'); - return $this->show_attachment('contact', $user_id, 'avatar', 'avatar.png'); } @@ -483,100 +474,93 @@ public function get_signature($contact_id) return $this->show_attachment('contact', $contact_id, 'signature', 'signature.png'); } + #[Authorize('delete-attachment')] public function delete_avatar($user_id): RedirectResponse { - Gate::authorize('delete-attachment'); $this->delete_attachment('avatar.png', 'contact', $user_id, 'avatar'); return Redirect::action([\App\Http\Controllers\PersonController::class, 'show'], $user_id); } + #[Authorize('show-event-attachment')] public function get_event_contract($event_id) { - Gate::authorize('show-event-attachment'); - return $this->show_attachment('event', $event_id, 'contract', null); } + #[Authorize('show-event-schedule')] public function get_event_schedule($event_id) { - Gate::authorize('show-event-schedule'); - return $this->show_attachment('event', $event_id, 'schedule', null); } + #[Authorize('show-event-evaluation')] public function get_event_evaluations($event_id) { - Gate::authorize('show-event-evaluation'); - return $this->show_attachment('event', $event_id, 'evaluations', null); } + #[Authorize('delete-attachment')] public function delete_event_evaluations($event_id): RedirectResponse { - Gate::authorize('delete-attachment'); $this->delete_attachment('evaluations.pdf', 'event', $event_id, 'evaluations'); return Redirect::action([\App\Http\Controllers\RetreatController::class, 'show'], $event_id); } + #[Authorize('delete-attachment')] public function delete_event_schedule($event_id): RedirectResponse { - Gate::authorize('delete-attachment'); $this->delete_attachment('schedule.pdf', 'event', $event_id, 'schedule'); return Redirect::action([\App\Http\Controllers\RetreatController::class, 'show'], $event_id); } + #[Authorize('delete-attachment')] public function delete_event_contract($event_id): RedirectResponse { - Gate::authorize('delete-attachment'); $this->delete_attachment('contract.pdf', 'event', $event_id, 'contract'); return Redirect::action([\App\Http\Controllers\RetreatController::class, 'show'], $event_id); } + #[Authorize('delete-attachment')] public function delete_event_group_photo($event_id): RedirectResponse { - Gate::authorize('delete-attachment'); $this->delete_attachment('group_photo.jpg', 'event', $event_id, 'group_photo'); return Redirect::action([\App\Http\Controllers\RetreatController::class, 'show'], $event_id); } + #[Authorize('show-event-group-photo')] public function get_event_group_photo($event_id) { - Gate::authorize('show-event-group-photo'); - return $this->show_attachment('event', $event_id, 'group_photo', null); } + #[Authorize('delete-attachment')] public function delete_asset_photo($asset_id): RedirectResponse { - Gate::authorize('delete-attachment'); $this->delete_attachment('asset_photo.jpg', 'asset', $asset_id, 'asset_photo'); return Redirect::action([\App\Http\Controllers\AssetController::class, 'show'], $asset_id); } + #[Authorize('show-asset')] public function get_asset_photo($asset_id) { - Gate::authorize('show-asset'); - return $this->show_attachment('asset', $asset_id, 'asset_photo', null); } + #[Authorize('show-attachment')] public function show_asset_attachment($asset_id, $file_name) { - Gate::authorize('show-attachment'); - return $this->show_attachment('asset', $asset_id, 'attachment', $file_name); } + #[Authorize('delete-attachment')] public function delete_asset_attachment($asset_id, $file_name): RedirectResponse { - Gate::authorize('delete-attachment'); - $this->delete_attachment($file_name, 'asset', $asset_id, 'attachment'); return Redirect::action([\App\Http\Controllers\AssetController::class, 'show'], $asset_id); @@ -585,9 +569,9 @@ public function delete_asset_attachment($asset_id, $file_name): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-attachment')] public function show(int $id): View { - Gate::authorize('show-attachment'); $attachment = \App\Models\Attachment::findOrFail($id); // $this->authorize('show-'.$attachment->entity); @@ -597,9 +581,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-attachment')] public function edit(int $id): View { - Gate::authorize('update-attachment'); $attachment = \App\Models\Attachment::findOrFail($id); return view('attachments.edit', compact('attachment')); @@ -609,10 +593,9 @@ public function edit(int $id): View * Update the specified resource in storage. * Really only used to allow for changing the description of a file */ + #[Authorize('update-attachment')] public function update(UpdateAttachmentRequest $request, int $id): RedirectResponse { - Gate::authorize('update-attachment'); - $attachment = \App\Models\Attachment::findOrFail($id); $attachment->description = $request->input('description'); $attachment->save(); @@ -625,9 +608,9 @@ public function update(UpdateAttachmentRequest $request, int $id): RedirectRespo /** * Display a listing of the resource. */ + #[Authorize('show-attachment')] public function index(): View { - Gate::authorize('show-attachment'); $attachments = \App\Models\Attachment::orderByDesc('upload_date')->paginate(25, ['*'], 'attachments'); return view('attachments.index', compact('attachments')); @@ -636,10 +619,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-attachment')] public function create(): RedirectResponse { - Gate::authorize('create-attachment'); - flash('Attachment create route is undefined. To create an attachment upload it using the asset, contact or event pages.')->warning()->important(); return Redirect::back(); // @@ -648,10 +630,9 @@ public function create(): RedirectResponse /** * Store a newly created resource in storage. */ + #[Authorize('create-attachment')] public function store(StoreAttachmentRequest $request): RedirectResponse { - Gate::authorize('create-attachment'); - flash('Storing attachment is undefined.')->warning()->important(); return Redirect::back(); @@ -660,10 +641,9 @@ public function store(StoreAttachmentRequest $request): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-attachment')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-attachment'); - flash('Deleting attachment method is undefined.')->warning()->important(); return Redirect::back(); diff --git a/app/Http/Controllers/AuditController.php b/app/Http/Controllers/AuditController.php index 16676f70c..f3ef0a8d1 100644 --- a/app/Http/Controllers/AuditController.php +++ b/app/Http/Controllers/AuditController.php @@ -7,35 +7,29 @@ use App\Models\User; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class AuditController extends Controller implements HasMiddleware +#[Middleware('auth')] +class AuditController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-audit')] public function index(): View { - Gate::authorize('show-audit'); $users = \App\Models\User::with('user')->orderBy('name')->pluck('name', 'id'); $audits = \App\Models\Audit::with('user')->orderBy('created_at', 'DESC')->paginate(25, ['*'], 'audits'); return view('admin.audits.index', compact('audits', 'users')); } + #[Authorize('show-audit')] public function index_type($user_id = null): View { - Gate::authorize('show-audit'); $users = \App\Models\User::with('user')->orderBy('name')->pluck('name', 'id'); $audits = \App\Models\Audit::with('user')->whereUserId($user_id)->orderBy('created_at', 'DESC')->paginate(25, ['*'], 'audits'); @@ -45,10 +39,10 @@ public function index_type($user_id = null): View /** * Show the form for creating a new resource. */ + #[Authorize('create-audit')] public function create(): RedirectResponse { // cannot manually create audits - Gate::authorize('create-audit'); flash('Manually creating an audit record is not allowed')->warning(); return Redirect::action([self::class, 'index']); @@ -57,10 +51,10 @@ public function create(): RedirectResponse /** * Store a newly created resource in storage. */ + #[Authorize('create-audit')] public function store(Request $request): RedirectResponse { // cannot manually create audits - Gate::authorize('create-audit'); flash('Manually storing an audit record is not allowed')->warning(); return Redirect::action([self::class, 'index']); @@ -69,10 +63,9 @@ public function store(Request $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-audit')] public function show(int $id): View { - Gate::authorize('show-audit'); - $audit = \App\Models\Audit::findOrFail($id); $old_values = collect($audit->old_values); $new_values = collect($audit->new_values); @@ -83,10 +76,10 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-audit')] public function edit(int $id): RedirectResponse { // cannot manually edit audits - Gate::authorize('update-audit'); flash('Manually editing an audit record is not allowed')->warning(); return Redirect::action([self::class, 'index']); @@ -95,10 +88,10 @@ public function edit(int $id): RedirectResponse /** * Update the specified resource in storage. */ + #[Authorize('update-audit')] public function update(Request $request, int $id): RedirectResponse { // cannot manually edit audits - Gate::authorize('update-audit'); flash('Manually updating an audit record is not allowed')->warning(); return Redirect::action([self::class, 'index']); @@ -107,19 +100,18 @@ public function update(Request $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-audit')] public function destroy(int $id): RedirectResponse { // cannot manually destroy audits - Gate::authorize('delete-audit'); flash('Manually destroying an audit record is not allowed')->warning(); return Redirect::action([self::class, 'index']); } + #[Authorize('show-audit')] public function search(): View { - Gate::authorize('show-audit'); - $users = User::whereProvider('google')->pluck('name', 'id'); $users->prepend('N/A', ''); @@ -131,9 +123,9 @@ public function search(): View return view('admin.audits.search', compact('users', 'models', 'actions')); } + #[Authorize('show-audit')] public function results(AuditSearchRequest $request): View { - Gate::authorize('show-audit'); if (! empty($request)) { $audits = Audit::filtered($request)->orderByDesc('created_at')->paginate(25, ['*'], 'audits'); $audits->appends($request->except('page')); diff --git a/app/Http/Controllers/Auth/ConfirmPasswordController.php b/app/Http/Controllers/Auth/ConfirmPasswordController.php index 81fa954a9..69d1f373e 100644 --- a/app/Http/Controllers/Auth/ConfirmPasswordController.php +++ b/app/Http/Controllers/Auth/ConfirmPasswordController.php @@ -4,9 +4,10 @@ use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ConfirmsPasswords; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Middleware; -class ConfirmPasswordController extends Controller implements HasMiddleware +#[Middleware('auth')] +class ConfirmPasswordController extends Controller { /* |-------------------------------------------------------------------------- @@ -27,11 +28,4 @@ class ConfirmPasswordController extends Controller implements HasMiddleware * @var string */ protected $redirectTo = '/home'; - - public static function middleware(): array - { - return [ - 'auth', - ]; - } } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index f5c7ce572..5a38d12dc 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -6,8 +6,7 @@ use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Routing\Controllers\Middleware; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Auth; use Laravel\Socialite\Facades\Socialite; use Symfony\Component\HttpFoundation\Request; @@ -16,7 +15,8 @@ // use Illuminate\Support\Facades\Redirect; -class LoginController extends Controller implements HasMiddleware +#[Middleware('guest', except: ['logout'])] +class LoginController extends Controller { /* |-------------------------------------------------------------------------- @@ -38,13 +38,6 @@ class LoginController extends Controller implements HasMiddleware */ protected $redirectTo = '/'; - public static function middleware(): array - { - return [ - new Middleware('guest', except: ['logout']), - ]; - } - /** * Redirect the user to the GitHub authentication page. */ diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 1aaecceb5..e69172f55 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -5,11 +5,12 @@ use App\Http\Controllers\Controller; use App\Models\User; use Illuminate\Foundation\Auth\RegistersUsers; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; -class RegisterController extends Controller implements HasMiddleware +#[Middleware('guest')] +class RegisterController extends Controller { /* |-------------------------------------------------------------------------- @@ -31,13 +32,6 @@ class RegisterController extends Controller implements HasMiddleware */ protected $redirectTo = '/home'; - public static function middleware(): array - { - return [ - 'guest', - ]; - } - /** * Get a validator for an incoming registration request. */ diff --git a/app/Http/Controllers/Auth/VerificationController.php b/app/Http/Controllers/Auth/VerificationController.php index e8af39be5..e98d53ad0 100644 --- a/app/Http/Controllers/Auth/VerificationController.php +++ b/app/Http/Controllers/Auth/VerificationController.php @@ -4,10 +4,12 @@ use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\VerifiesEmails; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Routing\Controllers\Middleware; +use Illuminate\Routing\Attributes\Controllers\Middleware; -class VerificationController extends Controller implements HasMiddleware +#[Middleware('auth')] +#[Middleware('signed', only: ['verify'])] +#[Middleware('throttle:6,1', only: ['verify', 'resend'])] +class VerificationController extends Controller { /* |-------------------------------------------------------------------------- @@ -28,13 +30,4 @@ class VerificationController extends Controller implements HasMiddleware * @var string */ protected $redirectTo = '/home'; - - public static function middleware(): array - { - return [ - 'auth', - new Middleware('signed', only: ['verify']), - new Middleware('throttle:6,1', only: ['verify', 'resend']), - ]; - } } diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 0fb22a3a4..43a325122 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -3,31 +3,23 @@ namespace App\Http\Controllers; use App\Http\Requests\AgcDonationsRequest; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Gate; use Illuminate\View\View; -class DashboardController extends Controller implements HasMiddleware +#[Middleware('auth')] +class DashboardController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-dashboard')] public function index(): View { - Gate::authorize('show-dashboard'); - return view('dashboard.index'); } + #[Authorize('show-dashboard')] public function agc($number_of_years = 5): View { - Gate::authorize('show-dashboard'); - $current_year = (int) (date('m') > 6) ? date('Y') + 1 : date('Y'); $years = []; @@ -108,10 +100,9 @@ public function agc($number_of_years = 5): View return view('dashboard.agc', compact('number_of_years', 'donors', 'agc_descriptions', 'data')); } + #[Authorize('show-donation')] public function agc_donations(AgcDonationsRequest $request): View { - Gate::authorize('show-donation'); - $current_year = (date('m') > 6) ? date('Y') + 1 : date('Y'); $fiscal_year = (! isset($request->fiscal_year)) ? $current_year : $request->fiscal_year; // fiscal_year 4-digit year @@ -149,9 +140,9 @@ public function agc_donations(AgcDonationsRequest $request): View return view('donations.results', compact('donations', 'all_donations')); } + #[Authorize('show-dashboard')] public function donation_description_chart(?int $category_id = null): View { - Gate::authorize('show-dashboard'); $descriptions = \App\Models\DonationType::active()->orderBy('name')->pluck('id', 'name'); if (! isset($category_id)) { $donation_type = \App\Models\DonationType::whereName('Retreat Funding')->first(); @@ -204,11 +195,10 @@ public function donation_description_chart(?int $category_id = null): View return view('dashboard.description', compact('donation_type', 'descriptions', 'data')); } + #[Authorize('show-dashboard')] public function events($year = null): View { // TODO: Create donut chart for average number of retreatants per event (get count of event_type_id) partipants/count(event_type_id) //useful for Ambassador goal of 40 (draw goal line) - Gate::authorize('show-dashboard'); - // default to current fiscal year if (! isset($year)) { $year = (date('m') > 6) ? date('Y') + 1 : date('Y'); diff --git a/app/Http/Controllers/DepartmentController.php b/app/Http/Controllers/DepartmentController.php index c473fa61a..d39027d08 100644 --- a/app/Http/Controllers/DepartmentController.php +++ b/app/Http/Controllers/DepartmentController.php @@ -5,24 +5,17 @@ use App\Http\Requests\StoreDepartmentRequest; use App\Http\Requests\UpdateDepartmentRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class DepartmentController extends Controller implements HasMiddleware +#[Middleware('auth')] +class DepartmentController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-department')] public function index(): View { - Gate::authorize('show-department'); - $departments = \App\Models\Department::orderBy('name')->get(); return view('admin.departments.index', compact('departments')); @@ -31,10 +24,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-department')] public function create(): View { - Gate::authorize('create-department'); - $parents = \App\Models\Department::orderBy('name')->pluck('name', 'id'); $parents->prepend('N/A', 0); @@ -44,10 +36,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-department')] public function store(StoreDepartmentRequest $request): RedirectResponse { - Gate::authorize('create-department'); - $department = new \App\Models\Department; $department->name = $request->input('name'); $department->label = $request->input('label'); @@ -66,10 +57,9 @@ public function store(StoreDepartmentRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-department')] public function show(int $id): View { - Gate::authorize('show-department'); - $department = \App\Models\Department::findOrFail($id); $children = \App\Models\Department::whereParentId($id)->get(); @@ -79,10 +69,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-department')] public function edit(int $id): View { - Gate::authorize('update-department'); - $department = \App\Models\Department::findOrFail($id); $parents = \App\Models\Department::orderBy('name')->pluck('name', 'id'); @@ -94,10 +83,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-department')] public function update(UpdateDepartmentRequest $request, int $id): RedirectResponse { - Gate::authorize('update-department'); - $department = \App\Models\Department::findOrFail($id); $department->name = $request->input('name'); @@ -116,9 +104,9 @@ public function update(UpdateDepartmentRequest $request, int $id): RedirectRespo /** * Remove the specified resource from storage. */ + #[Authorize('delete-department')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-department'); $department = \App\Models\Department::findOrFail($id); \App\Models\Department::destroy($id); diff --git a/app/Http/Controllers/DioceseController.php b/app/Http/Controllers/DioceseController.php index 74bcf7d07..ac6b0954d 100644 --- a/app/Http/Controllers/DioceseController.php +++ b/app/Http/Controllers/DioceseController.php @@ -5,28 +5,21 @@ use App\Http\Requests\StoreDioceseRequest; use App\Http\Requests\UpdateDioceseRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Arr; -use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class DioceseController extends Controller implements HasMiddleware +#[Middleware('auth')] +class DioceseController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-contact')] public function index(): View { - Gate::authorize('show-contact'); - $dioceses = \App\Models\Contact::whereSubcontactType(config('polanco.contact_type.diocese'))->orderBy('sort_name', 'asc')->with('addresses.state', 'phones', 'emails', 'websites', 'bishops.contact_b', 'parishes.contact_a')->paginate(25, ['*'], 'dioceses'); // dd($dioceses); @@ -36,9 +29,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-contact')] public function create(): View { - Gate::authorize('create-contact'); $states = \App\Models\StateProvince::orderby('name')->whereCountryId(config('polanco.country_id_usa'))->pluck('name', 'id'); $states->prepend('N/A', 0); @@ -59,10 +52,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-contact')] public function store(StoreDioceseRequest $request): RedirectResponse { - Gate::authorize('create-contact'); - $diocese = new \App\Models\Contact; $diocese->organization_name = $request->input('organization_name'); $diocese->display_name = $request->input('organization_name'); @@ -171,9 +163,9 @@ public function store(StoreDioceseRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-contact')] public function show(int $id): View { - Gate::authorize('show-contact'); $diocese = \App\Models\Contact::with('bishops.contact_b', 'parishes.contact_b', 'addresses.state', 'addresses.location', 'phones.location', 'emails.location', 'websites', 'note_diocese', 'a_relationships.relationship_type', 'a_relationships.contact_b', 'b_relationships.relationship_type', 'b_relationships.contact_a')->findOrFail($id); $touchpoints = \App\Models\Touchpoint::wherePersonId($id)->orderBy('touched_at', 'DESC')->paginate(25, ['*'], 'touchpoints'); $registrations = \App\Models\Registration::whereContactId($id)->orderBy('created_at', 'DESC')->paginate(25, ['*'], 'registrations'); @@ -199,9 +191,9 @@ public function show(int $id): View * // TODO: make create and edit bishop id multi-select with all bishops defaulting to selected on edit // TODO: consider making one primary bishop with multi-select for seperate auxilary bishops (new relationship) */ + #[Authorize('update-contact')] public function edit(int $id): View { - Gate::authorize('update-contact'); $diocese = \App\Models\Contact::with('primary_bishop.contact_b', 'bishops.contact_b', 'parishes.contact_b', 'address_primary.state', 'address_primary.location', 'phone_primary.location', 'phone_main_fax.location', 'email_primary.location', 'website_main', 'note_diocese')->findOrFail($id); if (empty($diocese->primary_bishop)) { $diocese->bishop_id = 0; @@ -255,10 +247,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-contact')] public function update(UpdateDioceseRequest $request, int $id): RedirectResponse { - Gate::authorize('update-contact'); - $diocese = \App\Models\Contact::with('bishops.contact_b', 'parishes.contact_b', 'address_primary.state', 'address_primary.location', 'phone_primary.location', 'phone_main_fax.location', 'email_primary.location', 'website_main', 'notes')->findOrFail($id); $diocese->organization_name = $request->input('organization_name'); $diocese->display_name = $request->input('display_name'); @@ -405,10 +396,9 @@ public function update(UpdateDioceseRequest $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-contact')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-contact'); - $diocese = \App\Models\Contact::findOrFail($id); \App\Models\Relationship::whereContactIdA($id)->delete(); \App\Models\Relationship::whereContactIdB($id)->delete(); diff --git a/app/Http/Controllers/DonationController.php b/app/Http/Controllers/DonationController.php index 29a8b15af..33cc78947 100644 --- a/app/Http/Controllers/DonationController.php +++ b/app/Http/Controllers/DonationController.php @@ -15,28 +15,21 @@ use App\Models\SquarespaceContribution; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class DonationController extends Controller implements HasMiddleware +#[Middleware('auth')] +class DonationController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-donation')] public function index(): View { - Gate::authorize('show-donation'); - // rather than using the active donation_descriptions from DonationType model, let's continue to show all of the existing donation_descriptions in the Donations table so that any that are not in the DonationType table can be cleaned up $donation_descriptions = DB::table('Donations')->selectRaw('MIN(donation_id) as donation_id, donation_description, count(*) as count')->groupBy('donation_description')->orderBy('donation_description')->whereNull('deleted_at')->get(); // dd($donation_descriptions); @@ -46,9 +39,9 @@ public function index(): View return view('donations.index', compact('donations', 'donation_descriptions')); } + #[Authorize('show-donation')] public function index_type($donation_id = null): View { - Gate::authorize('show-donation'); $donation_descriptions = DB::table('Donations')->selectRaw('MIN(donation_id) as donation_id, donation_description, count(*) as count')->groupBy('donation_description')->orderBy('donation_description')->whereNull('deleted_at')->get(); $donation = Donation::findOrFail($donation_id); $donation_description = $donation->donation_description; @@ -61,10 +54,9 @@ public function index_type($donation_id = null): View return view('donations.index', compact('donations', 'donation_descriptions', 'defaults')); // } + #[Authorize('show-donation')] public function search(): View { - Gate::authorize('show-donation'); - $descriptions = DonationType::active()->orderby('name')->pluck('name', 'name'); $descriptions->prepend('N/A', ''); @@ -74,9 +66,9 @@ public function search(): View return view('donations.search', compact('retreats', 'descriptions')); } + #[Authorize('show-donation')] public function results(DonationSearchRequest $request): View { - Gate::authorize('show-donation'); if (! empty($request)) { $all_donations = Donation::filtered($request)->orderBy('donation_date')->get(); $donations = Donation::filtered($request)->orderBy('donation_date')->paginate(25, ['*'], 'donations'); @@ -89,9 +81,9 @@ public function results(DonationSearchRequest $request): View return view('donations.results', compact('donations', 'all_donations')); } + #[Authorize('show-donation')] public function overpaid(): View { - Gate::authorize('show-donation'); $overpaid = DB::table('Donations_payment as p') ->select(DB::raw('d.contact_id, c.sort_name, d.donation_id, d.donation_date, ROUND(SUM(p.payment_amount),2) as paid, ROUND(d.donation_amount,2) as pledged')) ->leftjoin('Donations as d', 'd.donation_id', '=', 'p.donation_id') @@ -105,9 +97,9 @@ public function overpaid(): View } // TODO: add docs code here and create unit tests + #[Authorize('show-donation')] public function mergeable(): View { // contact id 5847 hardcoded for anonymous user - Gate::authorize('show-donation'); $mergeable = DB::table('Donations as d') ->select(DB::raw('CONCAT(d.contact_id,"-",d.event_id,"-",d.donation_description) as unique_value, COUNT(*) as donation_count, MAX(d.donation_date) as donation_date, MIN(d.donation_id) as min_donation_id, MAX(d.donation_id) as max_donation_id, MIN(c.sort_name) as sort_name, MIN(e.idnumber) as idnumber, MIN(e.title) as event_title, MIN(d.donation_description) as donation_description, MIN(d.contact_id) as contact_id')) ->leftjoin('event as e', 'd.event_id', '=', 'e.id') @@ -121,9 +113,9 @@ public function mergeable(): View } // TODO: add docs code here and create unit tests + #[Authorize('update-donation')] public function merge($first_donation_id = 0, $second_donation_id = 0): RedirectResponse { - Gate::authorize('update-donation'); $first_donation = Donation::findOrFail($first_donation_id); // target or destination donation $second_donation = Donation::findOrFail($second_donation_id); // source or donation being merged $second_donation_payments = Payment::whereDonationId($second_donation_id)->get(); @@ -178,10 +170,9 @@ public function merge($first_donation_id = 0, $second_donation_id = 0): Redirect return Redirect::action([self::class, 'mergeable']); } + #[Authorize('show-donation')] public function agc($year, DonationAgcRequest $request): View { - Gate::authorize('show-donation'); - if (! isset($year)) { $year = (date('m') > 6) ? date('Y') + 1 : date('Y'); } @@ -223,10 +214,9 @@ public function agc($year, DonationAgcRequest $request): View /** * Show the form for creating a new resource. */ + #[Authorize('create-donation')] public function create($id = null, $event_id = null, $type = null): View { - Gate::authorize('create-donation'); - $subcontact_type_id = (isset($type)) ? config('polanco.contact_type.'.$type) : null; if ($id > 0) { @@ -268,10 +258,9 @@ public function create($id = null, $event_id = null, $type = null): View * create and save new donation record * redirect to donation.index */ + #[Authorize('create-donation')] public function store(StoreDonationRequest $request): RedirectResponse { - Gate::authorize('create-donation'); - $donation = new Donation; $donation->contact_id = $request->input('donor_id'); if ($request->input('event_id') > 0) { @@ -309,9 +298,9 @@ public function store(StoreDonationRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-donation')] public function show(int $id): View { - Gate::authorize('show-donation'); $donation = Donation::with('payments', 'contact')->findOrFail($id); return view('donations.show', compact('donation')); // @@ -320,9 +309,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-donation')] public function edit(int $id): View { - Gate::authorize('update-donation'); // get this retreat's information $donation = Donation::with('payments', 'contact')->findOrFail($id); $descriptions = DonationType::active()->orderby('name')->pluck('name', 'name'); @@ -352,10 +341,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-donation')] public function update(UpdateDonationRequest $request, int $id): RedirectResponse { - Gate::authorize('update-donation'); - $donation = Donation::findOrFail($id); $donation->contact_id = $request->input('donor_id'); if ($request->input('event_id') > 0) { @@ -386,9 +374,9 @@ public function update(UpdateDonationRequest $request, int $id): RedirectRespons /** * Remove the specified resource from storage. */ + #[Authorize('delete-donation')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-donation'); $donation = Donation::findOrFail($id); $contact = Contact::findOrFail($donation->contact_id); // deletion of payments implied on the model @@ -413,9 +401,9 @@ public function destroy(int $id): RedirectResponse * this method will only be used for retreat offerings - other types of donations should be handled elsewhere * primary use is for creating retreat offering donations but will have ability to edit existing retreat offerings */ + #[Authorize('update-donation')] public function retreat_payments_update(Request $request): RedirectResponse { // I removed the permission check for update-payment as it seemed redundant to update-donation and it makes testing a little easier - Gate::authorize('update-donation'); if ($request->input('event_id')) { $event_id = $request->input('event_id'); } @@ -475,9 +463,9 @@ public function retreat_payments_update(Request $request): RedirectResponse } // TODO:: add unit test for this method + #[Authorize('update-donation')] public function process_deposits($event_id): RedirectResponse { - Gate::authorize('update-donation'); $event = Retreat::findOrFail($event_id); $event_deposits = Donation::whereEventId($event_id)->whereDonationDescription('Retreat Deposits')->get(); foreach ($event_deposits as $event_deposit) { @@ -496,9 +484,9 @@ public function process_deposits($event_id): RedirectResponse } // TODO:: add unit test for this method; creating method as proof of concept - need to come back and test + #[Authorize('update-donation')] public function unprocess_deposits($event_id): RedirectResponse { - Gate::authorize('update-donation'); $event = Retreat::findOrFail($event_id); $event_deposits = Donation::whereEventId($event_id)->whereDonationDescription('Retreat Funding')->get(); foreach ($event_deposits as $event_deposit) { diff --git a/app/Http/Controllers/DonationTypeController.php b/app/Http/Controllers/DonationTypeController.php index c7c69f523..53dcef589 100644 --- a/app/Http/Controllers/DonationTypeController.php +++ b/app/Http/Controllers/DonationTypeController.php @@ -5,23 +5,17 @@ use App\Http\Requests\StoreDonationTypeRequest; use App\Http\Requests\UpdateDonationTypeRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class DonationTypeController extends Controller implements HasMiddleware +#[Middleware('auth')] +class DonationTypeController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-donation-type')] public function index(): View { - Gate::authorize('show-donation-type'); $donation_types = \App\Models\DonationType::orderBy('label')->get(); return view('admin.donation_types.index', compact('donation_types')); @@ -30,20 +24,18 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-donation-type')] public function create(): View { - Gate::authorize('create-donation-type'); - return view('admin.donation_types.create'); } /** * Store a newly created resource in storage. */ + #[Authorize('create-donation-type')] public function store(StoreDonationTypeRequest $request): RedirectResponse { - Gate::authorize('create-donation-type'); - $donation_type = new \App\Models\DonationType; $donation_type->label = $request->input('label'); $donation_type->name = $request->input('name'); @@ -61,10 +53,9 @@ public function store(StoreDonationTypeRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-donation-type')] public function show(int $id): View { - Gate::authorize('show-donation-type'); - $donation_type = \App\Models\DonationType::findOrFail($id); return view('admin.donation_types.show', compact('donation_type')); @@ -73,10 +64,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-donation-type')] public function edit(int $id): View { - Gate::authorize('update-donation-type'); - $donation_type = \App\Models\DonationType::findOrFail($id); return view('admin.donation_types.edit', compact('donation_type')); // @@ -85,10 +75,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-donation-type')] public function update(UpdateDonationTypeRequest $request, int $id): RedirectResponse { - Gate::authorize('update-donation-type'); - $donation_type = \App\Models\DonationType::findOrFail($request->input('id')); $donation_type->name = $request->input('name'); $donation_type->label = $request->input('label'); @@ -105,10 +94,9 @@ public function update(UpdateDonationTypeRequest $request, int $id): RedirectRes /** * Remove the specified resource from storage. */ + #[Authorize('delete-donation-type')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-donation-type'); - $donation_type = \App\Models\DonationType::findOrFail($id); \App\Models\DonationType::destroy($id); diff --git a/app/Http/Controllers/DonorController.php b/app/Http/Controllers/DonorController.php index 82efce8a5..e7c81e795 100644 --- a/app/Http/Controllers/DonorController.php +++ b/app/Http/Controllers/DonorController.php @@ -6,25 +6,19 @@ use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\View\View; -class DonorController extends Controller implements HasMiddleware +#[Middleware('auth')] +class DonorController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-donor')] public function index(): View { - Gate::authorize('show-donor'); // only show donors that do not have a contact_id $donors = \App\Models\Donor::whereContactId(null)->orderBy('sort_name')->paginate(25, ['*'], 'donors'); @@ -36,11 +30,10 @@ public function index(): View * * @return \Illuminate\Http\Response */ + #[Authorize('create-donor')] public function create() { // will not be creating any PPD donor records - Gate::authorize('create-donor'); - return $this->index(); } @@ -49,18 +42,18 @@ public function create() * * @return \Illuminate\Http\Response */ + #[Authorize('create-donor')] public function store(Request $request) { // will not be creating any PPD donor records - Gate::authorize('create-donor'); } /** * Display the specified resource. */ + #[Authorize('show-donor')] public function show(int $id): View { - Gate::authorize('show-donor'); $donor = \App\Models\Donor::whereDonorId($id)->first(); // dd($donor,$id); $sortnames = \App\Models\Contact::whereSortName($donor->sort_name)->get(); @@ -74,10 +67,9 @@ public function show(int $id): View * * @return \Illuminate\Http\Response */ + #[Authorize('update-donor')] public function edit(int $id) { - Gate::authorize('update-donor'); - return $this->index(); } @@ -86,25 +78,21 @@ public function edit(int $id) * * @return \Illuminate\Http\Response */ - public function update(Request $request, int $id) - { - Gate::authorize('update-donor'); - } + #[Authorize('update-donor')] + public function update(Request $request, int $id) {} /** * Remove the specified resource from storage. * * @return \Illuminate\Http\Response */ - public function destroy(int $id) - { - Gate::authorize('delete-donor'); - } + #[Authorize('delete-donor')] + public function destroy(int $id) {} + #[Authorize('update-donor')] public function assign($donor_id, $contact_id): RedirectResponse { // dd($donor_id, $contact_id); - Gate::authorize('update-donor'); $donor = \App\Models\Donor::whereDonorId($donor_id)->first(); if (empty($donor->contact_id)) { $donor->contact_id = $contact_id; @@ -114,9 +102,9 @@ public function assign($donor_id, $contact_id): RedirectResponse return redirect()->action([self::class, 'index']); } + #[Authorize('create-contact')] public function add($donor_id): RedirectResponse { - Gate::authorize('create-contact'); $person = new \App\Models\Contact; $donor = \App\Models\Donor::findOrFail($donor_id); // dd($donor); diff --git a/app/Http/Controllers/ExportListController.php b/app/Http/Controllers/ExportListController.php index e6d68e937..c1bfe057c 100644 --- a/app/Http/Controllers/ExportListController.php +++ b/app/Http/Controllers/ExportListController.php @@ -6,24 +6,18 @@ use App\Http\Requests\UpdateExportListRequest; use Carbon\Carbon; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class ExportListController extends Controller implements HasMiddleware +#[Middleware('auth')] +class ExportListController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-export-list')] public function index(): View { - Gate::authorize('show-export-list'); $export_lists = \App\Models\ExportList::orderBy('label')->get(); return view('admin.export_lists.index', compact('export_lists')); @@ -32,9 +26,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-export-list')] public function create(): View { - Gate::authorize('create-export-list'); $export_list_types = config('polanco.export_list_types'); return view('admin.export_lists.create', compact('export_list_types')); @@ -43,10 +37,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-export-list')] public function store(StoreExportListRequest $request): RedirectResponse { - Gate::authorize('create-export-list'); - $export_list = new \App\Models\ExportList; $export_list->title = $request->input('title'); $export_list->label = $request->input('label'); @@ -68,10 +61,9 @@ public function store(StoreExportListRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-export-list')] public function show(int $id): View { - Gate::authorize('show-export-list'); - $export_list = \App\Models\ExportList::findOrFail($id); return view('admin.export_lists.show', compact('export_list')); @@ -80,10 +72,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-export-list')] public function edit(int $id): View { - Gate::authorize('update-export-list'); - $export_list = \App\Models\ExportList::findOrFail($id); $export_list_types = config('polanco.export_list_types'); @@ -93,10 +84,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-export-list')] public function update(UpdateExportListRequest $request, int $id): RedirectResponse { - Gate::authorize('update-export-list'); - $export_list = \App\Models\ExportList::findOrFail($id); $export_list->title = $request->input('title'); @@ -119,9 +109,9 @@ public function update(UpdateExportListRequest $request, int $id): RedirectRespo /** * Remove the specified resource from storage. */ + #[Authorize('delete-export-list')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-export-list'); $export_list = \App\Models\ExportList::findOrFail($id); \App\Models\ExportList::destroy($id); @@ -137,9 +127,9 @@ public function destroy(int $id): RedirectResponse * @param ExportListAGCRequest $request */ // public function agc(ExportListAGCRequest $request) + #[Authorize('show-export-list')] public function agc(): RedirectResponse { - Gate::authorize('show-export-list'); // $id = $request->input('id'); // $export_list = \App\Models\ExportList::findOrFail($id); // $start_date = $request->input('start_date'); diff --git a/app/Http/Controllers/GateController.php b/app/Http/Controllers/GateController.php index c62afda76..db6a71801 100644 --- a/app/Http/Controllers/GateController.php +++ b/app/Http/Controllers/GateController.php @@ -4,32 +4,26 @@ use Carbon\Carbon; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Gate; use Illuminate\View\View; use Twilio\Rest\Client; -class GateController extends Controller implements HasMiddleware +#[Middleware('auth')] +class GateController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-gate')] public function index(): View { - Gate::authorize('show-gate'); $touchpoints = \App\Models\Touchpoint::whereType('Gate activity')->orderBy('touched_at', 'desc')->with('person', 'staff')->paginate(25, ['*'], 'touchpoints'); return view('gate.index', compact('touchpoints')); } + #[Authorize('show-gate')] public function open(Request $request, $hours = null): View { - Gate::authorize('show-gate'); // Check to see if the user has permissions - $account_sid = config('settings.twilio_sid'); $auth_token = config('settings.twilio_token'); $twilio_number = config('settings.twilio_number'); @@ -79,10 +73,9 @@ public function open(Request $request, $hours = null): View return view('gate.open', compact('hours', 'message')); } + #[Authorize('show-gate')] public function close(Request $request): View { - Gate::authorize('show-gate'); // Check to see if the user has permissions - $account_sid = config('settings.twilio_sid'); $auth_token = config('settings.twilio_token'); $twilio_number = config('settings.twilio_number'); diff --git a/app/Http/Controllers/GiftCertificateController.php b/app/Http/Controllers/GiftCertificateController.php index 1596ac1d9..9cd2c515c 100644 --- a/app/Http/Controllers/GiftCertificateController.php +++ b/app/Http/Controllers/GiftCertificateController.php @@ -6,30 +6,24 @@ use App\Traits\SquareSpaceTrait; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Storage; use Illuminate\View\View; use PDF; -class GiftCertificateController extends Controller implements HasMiddleware +#[Middleware('auth')] +class GiftCertificateController extends Controller { use SquareSpaceTrait; - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-gift-certificate')] public function index(): View { - Gate::authorize('show-gift-certificate'); $gift_certificates = \App\Models\GiftCertificate::active()->orderBy('issue_date')->with(['purchaser', 'recipient'])->get(); $applied_gift_certificates = \App\Models\GiftCertificate::applied()->orderBy('issue_date')->with(['purchaser', 'recipient'])->get(); $expired_gift_certificates = \App\Models\GiftCertificate::expired()->orderBy('expiration_date')->with(['purchaser', 'recipient'])->get(); @@ -40,9 +34,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-gift-certificate')] public function create(Request $request): View { - Gate::authorize('create-gift-certificate'); // dd($request); $purchaser = collect(); $purchaser->name = ($request->filled('purchaser_name')) ? $request->input('purchaser_name') : null; @@ -65,10 +59,9 @@ public function create(Request $request): View /** * Store a newly created resource in storage. */ + #[Authorize('create-gift-certificate')] public function store(Request $request): RedirectResponse { - Gate::authorize('create-gift-certificate'); - $purchaser = $request->input('purchaser_name'); $recipient = $request->input('recipient_name'); @@ -149,9 +142,9 @@ public function store(Request $request): RedirectResponse * * @return \Illuminate\Http\Response */ + #[Authorize('show-gift-certificate')] public function show_pdf(int $id) { - Gate::authorize('show-gift-certificate'); $gift_certificate = \App\Models\GiftCertificate::findOrFail($id); $pdf = PDF::loadView('gift_certificates.certificate', compact('gift_certificate')); @@ -171,9 +164,9 @@ public function show_pdf(int $id) /** * Display the specified resource. */ + #[Authorize('show-gift-certificate')] public function show(int $id): View { - Gate::authorize('show-gift-certificate'); $gift_certificate = \App\Models\GiftCertificate::findOrFail($id); return view('gift_certificates.show', compact('gift_certificate')); @@ -182,9 +175,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-gift-certificate')] public function edit(int $id): View { - Gate::authorize('update-gift-certificate'); $gift_certificate = \App\Models\GiftCertificate::findOrFail($id); return view('gift_certificates.edit', compact('gift_certificate')); @@ -193,10 +186,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-gift-certificate')] public function update(Request $request, int $id): RedirectResponse { - Gate::authorize('update-gift-certificate'); - $gift_certificate = \App\Models\GiftCertificate::findOrFail($id); $gift_certificate->purchaser_id = $request->input('purchaser_id'); @@ -221,9 +213,9 @@ public function update(Request $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-gift_certificate')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-gift_certificate'); $gift_certificate = \App\Models\GiftCertificate::findOrFail($id); \App\Models\GiftCertificate::destroy($id); diff --git a/app/Http/Controllers/GroupController.php b/app/Http/Controllers/GroupController.php index b9185cbf0..ecbd82147 100644 --- a/app/Http/Controllers/GroupController.php +++ b/app/Http/Controllers/GroupController.php @@ -5,26 +5,20 @@ use App\Http\Requests\StoreGroupRequest; use App\Http\Requests\UpdateGroupRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class GroupController extends Controller implements HasMiddleware +#[Middleware('auth')] +class GroupController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-group')] public function index(): View { - Gate::authorize('show-group'); $groups = \App\Models\Group::whereIsActive(1)->orderBy('name')->with('members')->get(); foreach ($groups as $group) { $group->count = $group->members()->count(); @@ -36,20 +30,18 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-group')] public function create(): View { - Gate::authorize('create-group'); - return view('groups.create'); } /** * Store a newly created resource in storage. */ + #[Authorize('create-group')] public function store(StoreGroupRequest $request): RedirectResponse { - Gate::authorize('create-group'); - $group = new \App\Models\Group; $group->name = $request->input('name'); $group->title = $request->input('title'); @@ -68,9 +60,9 @@ public function store(StoreGroupRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-group')] public function show(int $id): View { - Gate::authorize('show-group'); $group = \App\Models\Group::findOrFail($id); $members = \App\Models\Contact::whereHas('groups', function ($query) use ($id) { $query->whereGroupId($id)->whereStatus('Added'); @@ -82,9 +74,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-group')] public function edit(int $id): View { - Gate::authorize('update-group'); $group = \App\Models\Group::findOrFail($id); return view('groups.edit', compact('group')); @@ -93,10 +85,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-group')] public function update(UpdateGroupRequest $request, int $id): RedirectResponse { - Gate::authorize('update-group'); - $group = \App\Models\Group::findOrFail($id); $group->name = $request->input('name'); $group->title = $request->input('title'); @@ -117,10 +108,9 @@ public function update(UpdateGroupRequest $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-group')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-group'); - $group = \App\Models\Group::findOrFail($id); \App\Models\Group::destroy($id); diff --git a/app/Http/Controllers/HealthController.php b/app/Http/Controllers/HealthController.php index 30c7c116c..76bdf7a31 100644 --- a/app/Http/Controllers/HealthController.php +++ b/app/Http/Controllers/HealthController.php @@ -3,27 +3,21 @@ namespace App\Http\Controllers; use DB; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Collection; // use Illuminate\Database\Eloquent\Collection; -use Illuminate\Support\Facades\Gate; use Illuminate\View\View; -class HealthController extends Controller implements HasMiddleware +#[Middleware('auth')] +class HealthController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Run all database health checks and display list of results */ + #[Authorize('show-admin-menu')] public function index(): View { - Gate::authorize('show-admin-menu'); $results = collect([]); $results->put('primary_address', $this->check_primary_address()); $results->put('primary_email', $this->check_primary_email()); @@ -43,9 +37,9 @@ public function index(): View /** * Run the primary address check to ensure there is one and only one primary email address for each contact_id */ + #[Authorize('show-admin-menu')] public function check_primary_address(): Collection { - Gate::authorize('show-admin-menu'); $results = collect([]); $address_primary = DB::table('address')->whereIsPrimary(1)->whereNull('deleted_at')->groupBy('contact_id')->havingRaw('count(id) > 1')->select('contact_id', 'street_address')->get(); @@ -55,9 +49,9 @@ public function check_primary_address(): Collection /** * Run the primary email check to ensure there is one and only one primary email address for each contact_id */ + #[Authorize('show-admin-menu')] public function check_primary_email(): Collection { - Gate::authorize('show-admin-menu'); $results = collect([]); $email_primary = DB::table('email')->whereIsPrimary(1)->whereNull('deleted_at')->groupBy('contact_id')->havingRaw('count(id) > 1')->select('contact_id', 'email')->get(); @@ -67,9 +61,9 @@ public function check_primary_email(): Collection /** * Run the primary address check to ensure there is one and only one primary email address for each contact_id */ + #[Authorize('show-admin-menu')] public function check_primary_phone(): Collection { - Gate::authorize('show-admin-menu'); $results = collect([]); $phone_primary = DB::table('phone')->whereIsPrimary(1)->whereNull('deleted_at')->groupBy('contact_id')->havingRaw('count(id) > 1')->select('contact_id', 'phone')->get(); @@ -79,9 +73,9 @@ public function check_primary_phone(): Collection /** * Run the abandoned payments check to ensure there are no payments with a deleted donation */ + #[Authorize('show-admin-menu')] public function check_abandoned_donations(): Collection { - Gate::authorize('show-admin-menu'); $results = collect([]); $abandoned_donations = DB::table('Donations') @@ -98,9 +92,9 @@ public function check_abandoned_donations(): Collection /** * Run the abandoned payments check to ensure there are no payments with a deleted donation */ + #[Authorize('show-admin-menu')] public function check_donations_with_zero_event_id(): Collection { - Gate::authorize('show-admin-menu'); $results = collect([]); $donations_with_zero_event_id = DB::table('Donations') @@ -117,9 +111,9 @@ public function check_donations_with_zero_event_id(): Collection /** * Run the abandoned payments check to ensure there are no payments with a deleted donation */ + #[Authorize('show-admin-menu')] public function check_abandoned_payments(): Collection { - Gate::authorize('show-admin-menu'); $results = collect([]); $abandoned_payments = DB::table('Donations_payment') @@ -136,9 +130,9 @@ public function check_abandoned_payments(): Collection /** * Run the abandoned registrations check to ensure there are no registrations (participant) with a deleted contact */ + #[Authorize('show-admin-menu')] public function check_abandoned_registrations(): Collection { - Gate::authorize('show-admin-menu'); $results = collect([]); $abandoned_registrations = DB::table('participant') @@ -155,9 +149,9 @@ public function check_abandoned_registrations(): Collection * Run the duplicate relationships check to ensure there are no duplicated relationships * // SELECT CONCAT(contact_id_a,":",contact_id_b,":",relationship_type_id) , COUNT(*) FROM relationship WHERE deleted_at IS NULL GROUP BY (CONCAT(contact_id_a,":",contact_id_b,":",relationship_type_id)) HAVING COUNT(*)>1 */ + #[Authorize('show-admin-menu')] public function check_duplicate_relationships(): Collection { - Gate::authorize('show-admin-menu'); $results = collect([]); $duplicate_relationships = DB::table('relationship') @@ -175,9 +169,9 @@ public function check_duplicate_relationships(): Collection * Check for primary addresses with no country * // SELECT * FROM address WHERE country_id = 0 AND deleted_at IS NULL AND street_address IS NOT NULL AND is_primary = 1; */ + #[Authorize('show-admin-menu')] public function check_address_with_no_country(): Collection { - Gate::authorize('show-admin-menu'); $results = collect([]); $address_with_no_country = DB::table('address') @@ -195,9 +189,9 @@ public function check_address_with_no_country(): Collection * Check for husbands with more than one wife and wives with more than one husband * // SELECT contact_id_b FROM relationship WHERE deleted_at IS NULL AND relationship_type_id=2 GROUP BY contact_id_b HAVING COUNT(contact_id_b)>1; */ + #[Authorize('show-admin-menu')] public function check_polygamy(): Collection { - Gate::authorize('show-admin-menu'); $results = collect([]); $husbands = DB::table('relationship') @@ -225,9 +219,9 @@ public function check_polygamy(): Collection * Check for primary addresses with no country * // SELECT * FROM address WHERE country_id = 0 AND deleted_at IS NULL AND street_address IS NOT NULL AND is_primary = 1; */ + #[Authorize('show-admin-menu')] public function check_anonymous_balance_transactions(): Collection { - Gate::authorize('show-admin-menu'); $results = collect([]); $anonymous_balance_transactions = DB::table('stripe_balance_transaction') diff --git a/app/Http/Controllers/LocationController.php b/app/Http/Controllers/LocationController.php index b8bcb20f0..b8820d36e 100644 --- a/app/Http/Controllers/LocationController.php +++ b/app/Http/Controllers/LocationController.php @@ -5,25 +5,18 @@ use App\Http\Requests\StoreLocationRequest; use App\Http\Requests\UpdateLocationRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Arr; -use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class LocationController extends Controller implements HasMiddleware +#[Middleware('auth')] +class LocationController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-location')] public function index(): View { - Gate::authorize('show-location'); - $location_types = config('polanco.locations_type'); $location_types = Arr::sort($location_types); @@ -32,10 +25,9 @@ public function index(): View return view('admin.locations.index', compact('locations', 'location_types')); } + #[Authorize('show-location')] public function index_type($type = null): View { - Gate::authorize('show-location'); - $location_types = config('polanco.locations_type'); $location_types = Arr::sort($location_types); @@ -47,10 +39,9 @@ public function index_type($type = null): View /** * Show the form for creating a new resource. */ + #[Authorize('create-location')] public function create(): View { - Gate::authorize('create-location'); - $location_types = config('polanco.locations_type'); $location_types = Arr::sort($location_types); @@ -66,10 +57,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-location')] public function store(StoreLocationRequest $request): RedirectResponse { - Gate::authorize('create-location'); - $location = new \App\Models\Location; $location->name = $request->input('name'); $location->description = $request->input('description'); @@ -92,10 +82,9 @@ public function store(StoreLocationRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-location')] public function show(int $id): View { - Gate::authorize('show-location'); - $location = \App\Models\Location::findOrFail($id); $children = \App\Models\Location::whereParentId($id)->orderBy('name')->get(); @@ -105,10 +94,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-location')] public function edit(int $id): View { - Gate::authorize('update-location'); - $location = \App\Models\Location::findOrFail($id); $location_types = config('polanco.locations_type'); @@ -126,10 +114,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-location')] public function update(UpdateLocationRequest $request, int $id): RedirectResponse { - Gate::authorize('update-location'); - $location = \App\Models\Location::findOrFail($id); $location->name = $request->input('name'); @@ -153,10 +140,9 @@ public function update(UpdateLocationRequest $request, int $id): RedirectRespons /** * Remove the specified resource from storage. */ + #[Authorize('delete-location')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-location'); - $location = \App\Models\Location::findOrFail($id); \App\Models\Location::destroy($id); diff --git a/app/Http/Controllers/MailgunController.php b/app/Http/Controllers/MailgunController.php index 93655f62c..0b1498515 100644 --- a/app/Http/Controllers/MailgunController.php +++ b/app/Http/Controllers/MailgunController.php @@ -6,14 +6,15 @@ use App\Traits\MailgunTrait; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Artisan; -use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; use Mailgun\Mailgun; -class MailgunController extends Controller implements HasMiddleware +#[Middleware('auth')] +class MailgunController extends Controller { use MailgunTrait; @@ -26,16 +27,10 @@ public function __construct() } } - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /* * Get and processes stored mailgun emails */ + #[Authorize('admin-mailgun')] public function get() { // TODO: create database factories for mailgun/messages, squarespace order/donation // TODO: write unit tests for stripe, mailgun, squarespace order/donation controllers @@ -45,8 +40,6 @@ public function get() // TODO: evaluate whether gift certificate retreat field is necessary in ss_order table or if it is better just to use the retreat field // TODO: for the address, attempt to normalize the state data (TX to Texas - may always be two state from squarespace - double check if that is the case) - Gate::authorize('admin-mailgun'); - $fail = Artisan::call('mailgun:get'); // because commands return 0 when successful the logic is somewhat reversed as 1 is failure and 0 is success if ($fail) { flash('Error: Mailgun messages were not successfully retrieved and processed. The site admin has been notified.')->error()->important(); @@ -57,20 +50,19 @@ public function get() return Redirect::action([MailgunController::class, 'index']); } + #[Authorize('admin-mailgun')] public function index(): View { // TODO: consider adding processed/unprocessed/all drowdown selector to filter results and combine processed and index blades into one - Gate::authorize('admin-mailgun'); $messages = Message::whereIsProcessed(0)->orderBy('mailgun_timestamp', 'desc')->paginate(25, ['*'], 'messages'); $messages_processed = Message::whereIsProcessed(1)->orderBy('mailgun_timestamp', 'desc')->paginate(25, ['*'], 'messages_processed'); return view('mailgun.index', compact('messages', 'messages_processed')); } + #[Authorize('admin-mailgun')] public function show($id): View { - Gate::authorize('admin-mailgun'); - $message = Message::with('contact_from', 'contact_to')->findOrFail($id); $body = explode("\n", $message->body); @@ -84,18 +76,17 @@ public function show($id): View * * @return \Illuminate\Http\Response */ + #[Authorize('admin-mailgun')] public function edit(int $id) { - Gate::authorize('admin-mailgun'); - // $message = Message::with('contact_from','contact_to')->findOrFail($id); // return view('mailgun.edit', compact('message')); return Redirect::action([MailgunController::class, 'index']); } + #[Authorize('admin-mailgun')] public function unprocess($id) { - Gate::authorize('admin-mailgun'); $message = Message::findOrFail($id); $message->is_processed = 0; $message->save(); @@ -109,10 +100,9 @@ public function unprocess($id) * Mailgun messages are retrieved from server and not created * Hence, this method is an empty stub. */ + #[Authorize('admin-mailgun')] public function create(): RedirectResponse { - Gate::authorize('admin-mailgun'); - return Redirect::action([MailgunController::class, 'index']); } @@ -121,10 +111,9 @@ public function create(): RedirectResponse * Mailgun messages are retrieved from server and not created or stored * Hence, this method is an empty stub. */ + #[Authorize('admin-mailgun')] public function store(Request $request): RedirectResponse { - Gate::authorize('admin-mailgun'); - return Redirect::action([MailgunController::class, 'index']); } @@ -136,10 +125,9 @@ public function store(Request $request): RedirectResponse * * @return Redirect to mailgun.index */ + #[Authorize('admin-mailgun')] public function update(Request $request, int $id): RedirectResponse { - Gate::authorize('admin-mailgun'); - return Redirect::action([MailgunController::class, 'index']); } @@ -149,10 +137,9 @@ public function update(Request $request, int $id): RedirectResponse * deleting is not needed and soft-deleting can cause sql integrity duplicate entry error * Hence, the delete method is an empty stub. */ + #[Authorize('admin-mailgun')] public function destroy(int $id): RedirectResponse { - Gate::authorize('admin-mailgun'); - // $message = Message::findOrFail($id); // Message::destroy($id); // flash('Mailgun message: '.$message->id.' deleted')->warning()->important(); diff --git a/app/Http/Controllers/OrganizationController.php b/app/Http/Controllers/OrganizationController.php index ba78c7ea2..247accd10 100644 --- a/app/Http/Controllers/OrganizationController.php +++ b/app/Http/Controllers/OrganizationController.php @@ -5,20 +5,14 @@ use App\Http\Requests\StoreOrganizationRequest; use App\Http\Requests\UpdateOrganizationRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class OrganizationController extends Controller implements HasMiddleware +#[Middleware('auth')] +class OrganizationController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. * @@ -26,9 +20,9 @@ public static function middleware(): array * * //TODO: subcontact_type dependent on order in database which is less than ideal really looking for where not a parish or diocese organization */ + #[Authorize('show-contact')] public function index(): View { - Gate::authorize('show-contact'); $organizations = \App\Models\Contact::with('addresses', 'phone_main_phone', 'email_primary', 'websites', 'subcontacttype')->organizations_generic()->orderBy('organization_name', 'asc')->paginate(25, ['*'], 'organizations'); $subcontact_types = \App\Models\ContactType::generic()->whereIsActive(1)->orderBy('label')->pluck('id', 'label'); @@ -36,9 +30,9 @@ public function index(): View return view('organizations.index', compact('organizations', 'subcontact_types')); // } + #[Authorize('show-contact')] public function index_type($subcontact_type_id): View { - Gate::authorize('show-contact'); $subcontact_types = \App\Models\ContactType::generic()->whereIsActive(1)->orderBy('label')->pluck('id', 'label'); $subcontact_type = \App\Models\ContactType::findOrFail($subcontact_type_id); $defaults = []; @@ -51,9 +45,9 @@ public function index_type($subcontact_type_id): View /** * Show the form for creating a new resource. */ + #[Authorize('create-contact')] public function create(): View { - Gate::authorize('create-contact'); $states = \App\Models\StateProvince::orderby('name')->whereCountryId(config('polanco.country_id_usa'))->pluck('name', 'id'); $states->prepend('N/A', 0); @@ -72,10 +66,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-contact')] public function store(StoreOrganizationRequest $request): RedirectResponse { - Gate::authorize('create-contact'); - $organization = new \App\Models\Contact; $organization->organization_name = $request->input('organization_name'); $organization->display_name = $request->input('organization_name'); @@ -179,9 +172,9 @@ public function store(StoreOrganizationRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-contact')] public function show(int $id): View { - Gate::authorize('show-contact'); $organization = \App\Models\Contact::with('addresses.state', 'addresses.location', 'phones.location', 'emails.location', 'websites', 'notes', 'phone_main_phone.location', 'a_relationships.relationship_type', 'a_relationships.contact_b', 'b_relationships.relationship_type', 'b_relationships.contact_a', 'event_registrations')->findOrFail($id); $donations = \App\Models\Donation::whereContactId($id)->with('payments')->orderBy('donation_date', 'DESC')->paginate(25, ['*'], 'donations'); $touchpoints = \App\Models\Touchpoint::wherePersonId($id)->orderBy('touched_at', 'DESC')->paginate(25, ['*'], 'touchpoints'); @@ -207,9 +200,9 @@ public function show(int $id): View * // TODO: make create and edit bishop id multi-select with all bishops defaulting to selected on edit * // TODO: consider making one primary bishop with multi-select for seperate auxilary bishops (new relationship) */ + #[Authorize('update-contact')] public function edit(int $id): View { - Gate::authorize('update-contact'); $organization = \App\Models\Contact::with('address_primary.state', 'address_primary.location', 'phone_main_phone.location', 'phone_main_fax.location', 'email_primary.location', 'website_main', 'notes')->findOrFail($id); $states = \App\Models\StateProvince::orderby('name')->whereCountryId(config('polanco.country_id_usa'))->pluck('name', 'id'); @@ -244,10 +237,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-contact')] public function update(UpdateOrganizationRequest $request, int $id): RedirectResponse { - Gate::authorize('update-contact'); - $organization = \App\Models\Contact::with('address_primary.state', 'address_primary.location', 'phone_main_phone.location', 'phone_main_fax.location', 'email_primary.location', 'website_main', 'note_organization')->findOrFail($id); $organization->organization_name = $request->input('organization_name'); $organization->display_name = $request->input('display_name'); @@ -386,9 +378,9 @@ public function update(UpdateOrganizationRequest $request, int $id): RedirectRes * * // TODO: delete addresses, emails, webpages, and phone numbers for persons, parishes, dioceses and organizations */ + #[Authorize('delete-contact')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-contact'); $organization = \App\Models\Organization::findOrFail($id); \App\Models\Relationship::whereContactIdA($id)->delete(); \App\Models\Relationship::whereContactIdB($id)->delete(); diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index f09151d64..071657dfb 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -6,7 +6,8 @@ use DateTime; use Exception; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Http; @@ -14,15 +15,9 @@ use Illuminate\View\View; use PDF; -class PageController extends Controller implements HasMiddleware +#[Middleware('auth')] +class PageController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - public function about(): View { return view('pages.about'); @@ -64,9 +59,9 @@ public function kitchen(): View return view('pages.kitchen'); } + #[Authorize('show-donation')] public function finance(): View { - Gate::authorize('show-donation'); $current_fiscal_year = (date('m') > 6) ? date('Y') + 1 : date('Y'); return view('pages.finance', compact('current_fiscal_year')); @@ -104,9 +99,9 @@ public function welcome(): View return view('welcome', compact('quote')); // } + #[Authorize('show-contact')] public function retreatantinforeport($idnumber): View { - Gate::authorize('show-contact'); Gate::authorize('show-registration'); $retreat = \App\Models\Retreat::whereIdnumber($idnumber)->firstOrFail(); @@ -123,18 +118,17 @@ public function retreatantinforeport($idnumber): View return view('reports.retreatantinfo2', compact('registrations')); // } + #[Authorize('show-contact')] public function contact_info_report($id): View { - Gate::authorize('show-contact'); - $person = \App\Models\Contact::findOrFail($id); return view('reports.contact_info', compact('person')); } + #[Authorize('show-donation')] public function finance_cash_deposit($day = null) { - Gate::authorize('show-donation'); if (is_null($day)) { $day = Carbon::now(); } else { // ensures that we are adding dashes to string prior to parsing in response to issue #448 @@ -153,10 +147,9 @@ public function finance_cash_deposit($day = null) return view('reports.finance.cash_deposit', compact('report_date', 'grouped_payments', 'grand_total')); } + #[Authorize('show-donation')] public function finance_cc_deposit($day = null) { - Gate::authorize('show-donation'); - if (is_null($day)) { $day = Carbon::now(); } else { @@ -175,19 +168,17 @@ public function finance_cc_deposit($day = null) } // TODO: why allow an empty donation id? + #[Authorize('show-donation')] public function finance_invoice($donation_id = null): View { - Gate::authorize('show-donation'); - $donation = \App\Models\Donation::with('payments', 'contact', 'retreat')->findOrFail($donation_id); return view('reports.finance.invoice', compact('donation')); } + #[Authorize('show-donation')] public function finance_agc_acknowledge(Request $request, $donation_id = null) { - Gate::authorize('show-donation'); - $donation = \App\Models\Donation::with('payments', 'contact', 'retreat')->findOrFail($donation_id); $snippets = \App\Models\Snippet::whereTitle('agc_acknowledge')->get(); @@ -228,10 +219,9 @@ public function finance_agc_acknowledge(Request $request, $donation_id = null) } } + #[Authorize('show-donation')] public function finance_retreatdonations($idnumber = null) { - Gate::authorize('show-donation'); - $retreat = \App\Models\Retreat::whereIdnumber($idnumber)->firstOrFail(); if (isset($retreat)) { $donations = \App\Models\Donation::whereEventId($retreat->id)->with('contact', 'payments')->get(); @@ -243,9 +233,9 @@ public function finance_retreatdonations($idnumber = null) } } + #[Authorize('show-donation')] public function finance_deposits() { - Gate::authorize('show-donation'); $donations = \App\Models\Donation::where('donation_description', 'Retreat Deposits')->whereDeletedAt(null)->where('donation_amount', '>', 0)->with('contact', 'payments', 'retreat')->get(); $payments = \App\Models\Payment::whereHas('donation', function ($query) { $query->where('donation_description', '=', 'Retreat Deposits'); @@ -262,9 +252,9 @@ public function finance_deposits() return view('reports.finance.deposits', compact('grouped_payments', 'payments')); } + #[Authorize('show-donation')] public function finance_reconcile_deposit_show($event_id = null) { - Gate::authorize('show-donation'); Gate::authorize('show-registration'); if (! isset($event_id)) { @@ -295,10 +285,9 @@ public function finance_reconcile_deposit_show($event_id = null) return view('reports.finance.reconcile_deposits', compact('diffpg', 'diffrg')); } + #[Authorize('show-contact')] public function retreatlistingreport($idnumber): View { - Gate::authorize('show-contact'); - $retreat = \App\Models\Retreat::whereIdnumber($idnumber)->firstOrFail(); $retreatants = \App\Models\Registration::whereCanceledAt(null) @@ -319,10 +308,9 @@ public function retreatlistingreport($idnumber): View return view('reports.retreatlisting', compact('registrations')); // } + #[Authorize('show-contact')] public function retreatrosterreport($idnumber): View { - Gate::authorize('show-contact'); - $retreat = \App\Models\Retreat::whereIdnumber($idnumber)->firstOrFail(); $retreatants = \App\Models\Registration::whereCanceledAt(null) ->whereEventId($retreat->id) @@ -342,10 +330,9 @@ public function retreatrosterreport($idnumber): View return view('reports.retreatroster', compact('registrations')); // } + #[Authorize('show-contact')] public function retreatrosterphonereport($idnumber): View { - Gate::authorize('show-contact'); - $retreat = \App\Models\Retreat::whereIdnumber($idnumber)->firstOrFail(); $retreatants = \App\Models\Registration::whereCanceledAt(null) ->whereEventId($retreat->id) @@ -365,10 +352,9 @@ public function retreatrosterphonereport($idnumber): View return view('reports.retreatrosterphone', compact('registrations')); // } + #[Authorize('show-registration')] public function retreatregistrations($idnumber): View { - Gate::authorize('show-registration'); - $retreat = \App\Models\Retreat::whereIdnumber($idnumber)->firstOrFail(); $registrations = \App\Models\Registration::whereCanceledAt(null) ->whereEventId($retreat->id) @@ -381,10 +367,9 @@ public function retreatregistrations($idnumber): View return view('reports.retreatregistrations', compact('registrations')); // } + #[Authorize('show-donation')] public function eoy_acknowledgment($contact_id = null, $start_date = null, $end_date = null) { - Gate::authorize('show-donation'); - if (! is_null($start_date)) { $start_date = $this->hyphenate_date($start_date); } @@ -446,59 +431,51 @@ public function eoy_acknowledgment($contact_id = null, $start_date = null, $end_ // return view('reports.finance.acknowledgment', compact('payments','contact', 'montserrat','start_date','end_date')); } + #[Authorize('show-admin-menu')] public function config_index(): View { - Gate::authorize('show-admin-menu'); - return view('admin.config.index'); } + #[Authorize('show-admin-menu')] public function config_application(): View { - Gate::authorize('show-admin-menu'); - return view('admin.config.application'); } + #[Authorize('show-admin-menu')] public function config_mail(): View { - Gate::authorize('show-admin-menu'); - return view('admin.config.mail'); } + #[Authorize('show-admin-menu')] public function config_gate(): View { - Gate::authorize('show-admin-menu'); - return view('admin.config.gate'); } + #[Authorize('show-admin-menu')] public function config_google_calendar(): View { - Gate::authorize('show-admin-menu'); - return view('admin.config.google_calendar'); } + #[Authorize('show-admin-menu')] public function config_google_client(): View { - Gate::authorize('show-admin-menu'); - return view('admin.config.google_client'); } + #[Authorize('show-admin-menu')] public function config_mailgun(): View { - Gate::authorize('show-admin-menu'); - return view('admin.config.mailgun'); } + #[Authorize('show-admin-menu')] public function config_twilio(): View { - Gate::authorize('show-admin-menu'); - return view('admin.config.twilio'); } diff --git a/app/Http/Controllers/ParishController.php b/app/Http/Controllers/ParishController.php index 3d06c62f6..47948f846 100644 --- a/app/Http/Controllers/ParishController.php +++ b/app/Http/Controllers/ParishController.php @@ -5,29 +5,23 @@ use App\Http\Requests\StoreParishRequest; use App\Http\Requests\UpdateParishRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Arr; -use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class ParishController extends Controller implements HasMiddleware +#[Middleware('auth')] +class ParishController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ + #[Authorize('show-contact')] public function index() { - Gate::authorize('show-contact'); $diocese = null; $dioceses = \App\Models\Contact::whereSubcontactType(config('polanco.contact_type.diocese'))->orderBy('sort_name', 'asc')->with('addresses.state', 'phones', 'emails', 'websites', 'bishops', 'primary_bishop')->get(); $parishes = \App\Models\Contact::whereSubcontactType(config('polanco.contact_type.parish'))->orderBy('organization_name', 'asc')->with('addresses.state', 'phones', 'emails', 'websites', 'pastor.contact_b.prefix', 'pastor.contact_b.suffix', 'diocese.contact_a')->get(); @@ -42,9 +36,9 @@ public function index() /** * Show the form for creating a new resource. */ + #[Authorize('create-contact')] public function create(): View { - Gate::authorize('create-contact'); $dioceses = \App\Models\Contact::whereSubcontactType(config('polanco.contact_type.diocese'))->orderby('organization_name')->pluck('organization_name', 'id'); $pastors = \App\Models\Contact::whereHas('b_relationships', function ($query) { $query->whereRelationshipTypeId(config('polanco.relationship_type.pastor'))->whereIsActive(1); @@ -63,9 +57,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-contact')] public function store(StoreParishRequest $request): RedirectResponse { - Gate::authorize('create-contact'); $parish = new \App\Models\Contact; $parish->organization_name = $request->input('organization_name'); $parish->display_name = $request->input('organization_name'); @@ -183,9 +177,9 @@ public function store(StoreParishRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-contact')] public function show(int $id): View { - Gate::authorize('show-contact'); $parish = \App\Models\Contact::with('pastor.contact_b', 'diocese.contact_a', 'addresses.state', 'addresses.location', 'phones.location', 'emails.location', 'websites', 'note_parish', 'parishioners.contact_b.address_primary.state', 'parishioners.contact_b.emails.location', 'parishioners.contact_b.phones.location', 'a_relationships.relationship_type', 'a_relationships.contact_b', 'b_relationships.relationship_type', 'b_relationships.contact_a')->findOrFail($id); $touchpoints = \App\Models\Touchpoint::wherePersonId($id)->orderBy('touched_at', 'DESC')->paginate(25, ['*'], 'touchpoints'); $registrations = \App\Models\Registration::whereContactId($id)->orderBy('created_at', 'DESC')->paginate(25, ['*'], 'registrations'); @@ -202,10 +196,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-contact')] public function edit(int $id): View { - Gate::authorize('update-contact'); - $parish = \App\Models\Contact::with('pastor.contact_b', 'diocese.contact_a', 'address_primary.state', 'address_primary.location', 'phone_primary.location', 'phone_main_fax', 'email_primary.location', 'website_main', 'note_parish')->findOrFail($id); $dioceses = \App\Models\Contact::whereSubcontactType(config('polanco.contact_type.diocese'))->orderby('organization_name')->pluck('organization_name', 'id'); @@ -259,10 +252,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-contact')] public function update(UpdateParishRequest $request, int $id): RedirectResponse { - Gate::authorize('update-contact'); - $parish = \App\Models\Contact::with('pastor.contact_a', 'diocese.contact_a', 'address_primary.state', 'address_primary.location', 'phone_primary.location', 'phone_main_fax', 'email_primary.location', 'website_main', 'notes')->findOrFail($request->input('id')); $parish->organization_name = $request->input('organization_name'); $parish->display_name = $request->input('display_name'); @@ -427,9 +419,9 @@ public function update(UpdateParishRequest $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-contact')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-contact'); $parish = \App\Models\Parish::findOrFail($id); \App\Models\Relationship::whereContactIdA($id)->delete(); \App\Models\Relationship::whereContactIdB($id)->delete(); @@ -454,9 +446,9 @@ public function destroy(int $id): RedirectResponse return Redirect::action([self::class, 'index']); } + #[Authorize('show-contact')] public function parish_index_by_diocese($diocese_id): View { - Gate::authorize('show-contact'); $diocese = \App\Models\Contact::findOrFail($diocese_id); // dd($diocese); $dioceses = \App\Models\Contact::whereSubcontactType(config('polanco.contact_type.diocese'))->orderBy('sort_name', 'asc')->with('addresses.state', 'phones', 'emails', 'websites', 'bishops', 'primary_bishop')->get(); diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 810a7593f..ce094b416 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -6,26 +6,21 @@ use App\Http\Requests\StorePaymentRequest; use App\Http\Requests\UpdatePaymentRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class PaymentController extends Controller implements HasMiddleware +#[Middleware('auth')] +class PaymentController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-payment')] public function index(): View { - Gate::authorize('show-payment'); $payments = \App\Models\Payment::orderBy('payment_date', 'desc')->with('donation.retreat')->paginate(25, ['*'], 'payments'); // dd($donations); @@ -55,10 +50,9 @@ public function create($donation_id = 0) } } + #[Authorize('show-payment')] public function search(): View { - Gate::authorize('show-payment'); - $payment_methods = config('polanco.payment_method'); $payment_methods[''] = 'N/A'; @@ -68,9 +62,9 @@ public function search(): View return view('payments.search', compact('payment_methods', 'descriptions')); } + #[Authorize('show-payment')] public function results(PaymentSearchRequest $request): View { - Gate::authorize('show-payment'); if (! empty($request)) { $all_payments = \App\Models\Payment::filtered($request)->orderBy('payment_date')->get(); $payments = \App\Models\Payment::filtered($request)->orderBy('payment_date')->paginate(25, ['*'], 'payments'); @@ -86,9 +80,9 @@ public function results(PaymentSearchRequest $request): View /** * Store a newly created resource in storage. */ + #[Authorize('create-payment')] public function store(StorePaymentRequest $request): RedirectResponse { - Gate::authorize('create-payment'); // dd($request); $donation = \App\Models\Donation::findOrFail($request->input('donation_id')); @@ -115,9 +109,9 @@ public function store(StorePaymentRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-payment')] public function show(int $id): View { - Gate::authorize('show-payment'); $payment = \App\Models\Payment::with('donation.retreat', 'donation.contact', 'balance_transaction')->findOrFail($id); // dd($payment); @@ -127,9 +121,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-payment')] public function edit(int $id): View { - Gate::authorize('update-payment'); // get this retreat's information $payment = \App\Models\Payment::with('donation.contact', 'donation.retreat')->findOrFail($id); $payment_methods = config('polanco.payment_method'); @@ -140,10 +134,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-payment')] public function update(UpdatePaymentRequest $request, int $id): RedirectResponse { - Gate::authorize('update-payment'); - $payment = \App\Models\Payment::findOrFail($id); $payment->payment_amount = $request->input('payment_amount'); $payment->payment_date = $request->input('payment_date'); @@ -167,9 +160,9 @@ public function update(UpdatePaymentRequest $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-payment')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-payment'); $payment = \App\Models\Payment::findOrFail($id); \App\Models\Payment::destroy($id); diff --git a/app/Http/Controllers/PermissionController.php b/app/Http/Controllers/PermissionController.php index 0b40539f5..71b59bcb1 100644 --- a/app/Http/Controllers/PermissionController.php +++ b/app/Http/Controllers/PermissionController.php @@ -4,23 +4,18 @@ use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class PermissionController extends Controller implements HasMiddleware +#[Middleware('auth')] +class PermissionController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-permission')] public function index(Request $request): View { - Gate::authorize('show-permission'); $actions = [ '' => 'N/A', 'create' => 'create', @@ -85,19 +80,18 @@ public function index(Request $request): View /** * Show the form for creating a new resource. */ + #[Authorize('create-permission')] public function create(): View { - Gate::authorize('create-permission'); - return view('admin.permissions.create'); } /** * Store a newly created resource in storage. */ + #[Authorize('create-permission')] public function store(Request $request): RedirectResponse { - Gate::authorize('create-permission'); $permission = new \App\Models\Permission; $permission->name = $request->input('name'); $permission->display_name = $request->input('display_name'); @@ -112,9 +106,9 @@ public function store(Request $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-permission')] public function show(int $id): View { - Gate::authorize('show-permission'); $permission = \App\Models\Permission::with('roles.users')->findOrFail($id); $roles = \App\Models\Role::orderBy('name')->pluck('name', 'id'); @@ -124,9 +118,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-permission')] public function edit(int $id): View { - Gate::authorize('update-permission'); $permission = \App\Models\Permission::findOrFail($id); return view('admin.permissions.edit', compact('permission')); @@ -135,9 +129,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-permission')] public function update(Request $request, int $id): RedirectResponse { - Gate::authorize('update-permission'); $permission = \App\Models\Permission::findOrFail($request->input('id')); $permission->name = $request->input('name'); $permission->display_name = $request->input('display_name'); @@ -152,10 +146,9 @@ public function update(Request $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-permission')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-permission'); - $permission = \App\Models\Permission::findOrFail($id); \App\Models\Permission::destroy($id); @@ -165,9 +158,9 @@ public function destroy(int $id): RedirectResponse return Redirect::action([self::class, 'index']); } + #[Authorize('update-permission')] public function update_roles(Request $request): RedirectResponse { - Gate::authorize('update-permission'); Gate::authorize('update-role'); $permission = \App\Models\Permission::findOrFail($request->input('id')); $permission->roles()->detach(); diff --git a/app/Http/Controllers/PersonController.php b/app/Http/Controllers/PersonController.php index 1d80d026d..a8afaf0be 100644 --- a/app/Http/Controllers/PersonController.php +++ b/app/Http/Controllers/PersonController.php @@ -7,7 +7,8 @@ use Carbon\Carbon; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Storage; @@ -15,30 +16,23 @@ use Illuminate\Validation\Rule; use Illuminate\View\View; -class PersonController extends Controller implements HasMiddleware +#[Middleware('auth')] +class PersonController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-contact')] public function index(): View { - Gate::authorize('show-contact'); - $persons = \App\Models\Contact::whereContactType(config('polanco.contact_type.individual'))->orderBy('sort_name', 'asc')->with('address_primary.state', 'phones', 'emails', 'websites', 'parish.contact_a.address_primary', 'prefix', 'suffix')->paginate(25, ['*'], 'persons'); return view('persons.index', compact('persons')); } + #[Authorize('show-contact')] public function lastnames($letter = null): View { - Gate::authorize('show-contact'); $persons = \App\Models\Contact::whereContactType(config('polanco.contact_type.individual'))->orderBy('sort_name', 'asc')->with('addresses.state', 'phones', 'emails', 'websites', 'parish.contact_a')->where('last_name', 'LIKE', $letter.'%')->paginate(25, ['*'], 'persons'); return view('persons.index', compact('persons')); @@ -47,9 +41,9 @@ public function lastnames($letter = null): View /** * Show the form for creating a new resource. */ + #[Authorize('create-contact')] public function create(): View { - Gate::authorize('create-contact'); $parishes = \App\Models\Contact::whereSubcontactType(config('polanco.contact_type.parish'))->orderBy('organization_name', 'asc')->with('address_primary.state', 'diocese.contact_a')->get(); $parish_list[0] = 'N/A'; // while probably not the most efficient way of doing this it gets me the result @@ -108,9 +102,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-contact')] public function store(StorePersonRequest $request): RedirectResponse { - Gate::authorize('create-contact'); $person = new \App\Models\Contact; $person->contact_type = $request->input('contact_type'); @@ -630,9 +624,9 @@ public function store(StorePersonRequest $request): RedirectResponse * * @return \Illuminate\Http\Response */ + #[Authorize('show-contact')] public function show(int $id) { - Gate::authorize('show-contact'); $person = \App\Models\Contact::with( 'addresses.country', 'addresses.location', @@ -723,10 +717,9 @@ public function show(int $id) * @return \Illuminate\Http\Response * TODO: Shift suggestion - review these instances for dynamic validation rules - handle in a custom request like EnvelopeRequest */ + #[Authorize('show-contact')] public function envelope(int $id, Request $request) { - Gate::authorize('show-contact'); - // default size = 10; logo = false $size = (string) '10'; $logo = (bool) 0; @@ -773,9 +766,9 @@ public function envelope(int $id, Request $request) /** * Show the form for editing the specified resource. */ + #[Authorize('update-contact')] public function edit(int $id): View { - Gate::authorize('update-contact'); $person = \App\Models\Contact::with('prefix', 'suffix', 'addresses.location', 'emails.location', 'phones.location', 'websites', 'parish', 'emergency_contact', 'notes')->findOrFail($id); // dd($person); @@ -930,10 +923,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-contact')] public function update(UpdatePersonRequest $request, int $id): RedirectResponse { - Gate::authorize('update-contact'); - $person = \App\Models\Contact::with('addresses.location', 'emails.location', 'phones.location', 'websites', 'emergency_contact', 'parish')->findOrFail($id); $person->contact_type = $request->input('contact_type'); @@ -1562,10 +1554,9 @@ public function update(UpdatePersonRequest $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-contact')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-contact'); - // TODO: consider creating a restore/{id} or undelete/{id} $person = \App\Models\Contact::findOrFail($id); // delete existing groups and relationships when deleting user @@ -1591,11 +1582,10 @@ public function destroy(int $id): RedirectResponse return Redirect::action([self::class, 'index']); } + #[Authorize('delete-duplicate')] public function merge_destroy($id, $return_id): RedirectResponse { // TODO: consider creating a restore/{id} or undelete/{id} - Gate::authorize('delete-duplicate'); - $person = \App\Models\Contact::findOrFail($id); // delete existing groups and relationships when deleting user @@ -1694,10 +1684,9 @@ public function volunteers() return $this->role(config('polanco.group_id.volunteer')); } + #[Authorize('show-contact')] public function role($group_id): View { - Gate::authorize('show-contact'); - $persons = \App\Models\Contact::with('groups', 'address_primary', 'ambassador_events')->whereHas('groups', function ($query) use ($group_id) { $query->where('group_id', '=', $group_id)->whereStatus('Added'); })->orderBy('sort_name')->get(); @@ -1758,9 +1747,9 @@ public function role($group_id): View } */ + #[Authorize('update-contact')] public function save_relationship($field, $contact_id_a, $contact_id_b, $relationship_type) { - Gate::authorize('update-contact'); Gate::authorize('update-relationship'); if ($field > 0) { @@ -1773,10 +1762,9 @@ public function save_relationship($field, $contact_id_a, $contact_id_b, $relatio } } + #[Authorize('update-contact')] public function duplicates(): View { - Gate::authorize('update-contact'); - $duplicates = \App\Models\Contact::whereIn('id', function ($query) { $query->select('id')->from('contact')->groupBy('sort_name')->whereDeletedAt(null)->havingRaw('count(*)>1'); })->orderBy('sort_name')->paginate(25, ['*'], 'duplicates'); @@ -1785,9 +1773,9 @@ public function duplicates(): View return view('persons.duplicates', compact('duplicates')); } + #[Authorize('update-contact')] public function merge($contact_id, $merge_id = null) { - Gate::authorize('update-contact'); Gate::authorize('update-relationship'); Gate::authorize('update-attachment'); Gate::authorize('update-touchpoint'); diff --git a/app/Http/Controllers/RegistrationController.php b/app/Http/Controllers/RegistrationController.php index dde170d6f..c745c3e33 100644 --- a/app/Http/Controllers/RegistrationController.php +++ b/app/Http/Controllers/RegistrationController.php @@ -13,34 +13,26 @@ use Auth; use Carbon\Carbon; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Routing\Controllers\Middleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Str; use Illuminate\View\View; -class RegistrationController extends Controller implements HasMiddleware +#[Middleware('auth', except: ['confirmAttendance'])] +class RegistrationController extends Controller { use SquareSpaceTrait; - public static function middleware(): array - { - return [ - new Middleware('auth', except: ['confirmAttendance']), - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-registration')] public function index(): View { - Gate::authorize('show-registration'); - $registrations = \App\Models\Registration::with('contact.suffix')->with('contact.prefix') ->whereHas('retreat', function ($query) { $query->where('end_date', '>=', date('Y-m-d')); @@ -54,10 +46,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-registration')] public function create(): View { - Gate::authorize('create-registration'); - $retreats = \App\Models\Retreat::select(DB::raw('CONCAT(idnumber, "-", title, " (",DATE_FORMAT(start_date,"%m-%d-%Y"),")") as description'), 'id')->where('end_date', '>', Carbon::today()->subWeek())->where('is_active', '=', 1)->orderBy('start_date')->pluck('description', 'id'); $retreats->prepend('Unassigned', 0); $retreatants = \App\Models\Contact::whereContactType(config('polanco.contact_type.individual'))->orderBy('sort_name')->pluck('sort_name', 'id'); @@ -75,9 +66,9 @@ public function create(): View return view('registrations.create', compact('retreats', 'retreatants', 'rooms', 'defaults')); } + #[Authorize('create-registration')] public function add($id = null): View { - Gate::authorize('create-registration'); $retreats = \App\Models\Retreat::select(DB::raw('CONCAT(idnumber, "-", title, " (",DATE_FORMAT(start_date,"%m-%d-%Y"),")") as description'), 'id')->where('end_date', '>', Carbon::today()->subWeek())->where('is_active', '=', 1)->orderBy('start_date')->pluck('description', 'id'); $retreats->prepend('Unassigned', 0); $retreatant = \App\Models\Contact::findOrFail($id); @@ -104,10 +95,9 @@ public function add($id = null): View return view('registrations.create', compact('retreats', 'retreatants', 'rooms', 'defaults')); } + #[Authorize('create-registration')] public function add_group($id): View { - Gate::authorize('create-registration'); - $retreats = \App\Models\Retreat::select(DB::raw('CONCAT(idnumber, "-", title, " (",DATE_FORMAT(start_date,"%m-%d-%Y"),")") as description'), 'id')->where('end_date', '>', Carbon::today()->subWeek())->orderBy('start_date')->pluck('description', 'id'); $retreats->prepend('Unassigned', 0); // if the $id parameter is not a valid group fail with 404 @@ -129,10 +119,9 @@ public function add_group($id): View // dd($retreatants); } + #[Authorize('create-registration')] public function register($retreat_id = 0, $contact_id = 0): View { - Gate::authorize('create-registration'); - if ($retreat_id > 0) { $retreats = \App\Models\Retreat::select(DB::raw('CONCAT(idnumber, "-", title, " (",DATE_FORMAT(start_date,"%m-%d-%Y"),")") as description'), 'id')->whereId($retreat_id)->orderBy('start_date')->pluck('description', 'id'); } else { @@ -176,9 +165,9 @@ public function register($retreat_id = 0, $contact_id = 0): View /** * Store a newly created resource in storage. */ + #[Authorize('create-registration')] public function store(StoreRegistrationRequest $request): RedirectResponse { - Gate::authorize('create-registration'); $rooms = $request->input('rooms'); $num_registrants = $request->input('num_registrants'); // TODO: Should we check and verify that the contact type is an organization to allow multiselect or just allow any registration to book multiple rooms? @@ -252,10 +241,9 @@ public function store(StoreRegistrationRequest $request): RedirectResponse // return Redirect::action([\App\Http\Controllers\PersonController::class, 'show'], $registration->contact_id); } + #[Authorize('create-registration')] public function store_group(StoreGroupRegistrationRequest $request): RedirectResponse { - Gate::authorize('create-registration'); - $retreat = \App\Models\Retreat::findOrFail($request->input('event_id')); $group = \App\Models\Group::findOrFail($request->input('group_id')); $group_members = \App\Models\GroupContact::whereGroupId($group->id)->whereStatus('Added')->get(); @@ -292,9 +280,9 @@ public function store_group(StoreGroupRegistrationRequest $request): RedirectRes /** * Display the specified resource. */ + #[Authorize('show-registration')] public function show(int $id): View { - Gate::authorize('show-registration'); $registration = \App\Models\Registration::with('retreat', 'retreatant', 'room')->findOrFail($id); return view('registrations.show', compact('registration')); // @@ -303,10 +291,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-registration')] public function edit(int $id): View { - Gate::authorize('update-registration'); - $registration = \App\Models\Registration::with('retreatant', 'retreat', 'room')->findOrFail($id); $retreatant = \App\Models\Contact::findOrFail($registration->contact_id); $retreats = \App\Models\Retreat::select(DB::raw('CONCAT(idnumber, "-", title, " (",DATE_FORMAT(start_date,"%m-%d-%Y"),")") as description'), 'id')->where('end_date', '>', Carbon::today())->orderBy('start_date')->pluck('description', 'id'); @@ -348,10 +335,9 @@ public function edit(int $id): View * * @return \Illuminate\Http\Response */ + #[Authorize('update-registration')] public function update(UpdateRegistrationRequest $request, int $id) { - Gate::authorize('update-registration'); - $registration = \App\Models\Registration::findOrFail($request->input('id')); $retreat = \App\Models\Retreat::findOrFail($request->input('event_id')); $contact = \App\Models\Contact::findOrFail($registration->contact_id); @@ -417,10 +403,9 @@ public function update(UpdateRegistrationRequest $request, int $id) /** * Remove the specified resource from storage. */ + #[Authorize('delete-registration')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-registration'); - $registration = \App\Models\Registration::findOrFail($id); $retreat = \App\Models\Retreat::findOrFail($registration->event_id); @@ -434,10 +419,9 @@ public function destroy(int $id): RedirectResponse return Redirect::action([self::class, 'index']); } + #[Authorize('update-registration')] public function confirm($id): RedirectResponse { - Gate::authorize('update-registration'); - $registration = \App\Models\Registration::findOrFail($id); $registration->registration_confirm_date = Carbon::now(); $registration->save(); @@ -445,9 +429,9 @@ public function confirm($id): RedirectResponse return redirect()->back(); } + #[Authorize('update-registration')] public function attend($id): RedirectResponse { - Gate::authorize('update-registration'); $registration = \App\Models\Registration::findOrFail($id); $registration->attendance_confirm_date = Carbon::now(); $registration->save(); @@ -455,9 +439,9 @@ public function attend($id): RedirectResponse return redirect()->back(); } + #[Authorize('update-registration')] public function arrive($id): RedirectResponse { - Gate::authorize('update-registration'); $registration = \App\Models\Registration::findOrFail($id); $registration->arrived_at = Carbon::now(); $registration->save(); @@ -465,9 +449,9 @@ public function arrive($id): RedirectResponse return redirect()->back(); } + #[Authorize('update-registration')] public function depart($id): RedirectResponse { - Gate::authorize('update-registration'); $registration = \App\Models\Registration::findOrFail($id); $registration->departed_at = Carbon::now(); $registration->save(); @@ -475,9 +459,9 @@ public function depart($id): RedirectResponse return redirect()->back(); } + #[Authorize('update-registration')] public function cancel($id): RedirectResponse { - Gate::authorize('update-registration'); $registration = \App\Models\Registration::findOrFail($id); $registration->canceled_at = Carbon::now(); $registration->save(); @@ -485,9 +469,9 @@ public function cancel($id): RedirectResponse return redirect()->back(); } + #[Authorize('update-registration')] public function waitlist($id): RedirectResponse { - Gate::authorize('update-registration'); $registration = \App\Models\Registration::findOrFail($id); $registration->status_id = config('polanco.registration_status_id.waitlist'); $registration->save(); @@ -495,9 +479,9 @@ public function waitlist($id): RedirectResponse return redirect()->back(); } + #[Authorize('update-registration')] public function offwaitlist($id): RedirectResponse { - Gate::authorize('update-registration'); $registration = \App\Models\Registration::findOrFail($id); $registration->status_id = config('polanco.registration_status_id.registered'); $registration->save(); @@ -505,10 +489,9 @@ public function offwaitlist($id): RedirectResponse return redirect()->back(); } + #[Authorize('show-registration')] public function registrationEmail(Registration $participant): RedirectResponse { - Gate::authorize('show-registration'); - // 1. Get a primary email address for participant. $primaryEmail = $participant->contact->primaryEmail()->first(); @@ -537,9 +520,9 @@ public function registrationEmail(Registration $participant): RedirectResponse return redirect('person/'.$participant->contact->id); } + #[Authorize('update-registration')] public function send_confirmation_email($id): RedirectResponse { - Gate::authorize('update-registration'); $registration = \App\Models\Registration::findOrFail($id); $current_user = Auth::user(); $primary_email = $registration->retreatant->email_primary_text; diff --git a/app/Http/Controllers/RelationshipController.php b/app/Http/Controllers/RelationshipController.php index cde41276f..b6c7f6097 100644 --- a/app/Http/Controllers/RelationshipController.php +++ b/app/Http/Controllers/RelationshipController.php @@ -6,26 +6,20 @@ use DB; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class RelationshipController extends Controller implements HasMiddleware +#[Middleware('auth')] +class RelationshipController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-relationship')] public function index(): View { - Gate::authorize('show-relationship'); $relationships = \App\Models\Relationship::paginate(25, ['*'], 'relationships'); return view('relationships.index', compact('relationships')); // @@ -34,9 +28,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-relationship')] public function create(): RedirectResponse { // TODO: stub: re-evaluate handling of relationships to refactor person controller to avoid repetition - Gate::authorize('create-relationship'); flash('Relationships cannot be directly created as they are managed via contacts')->error(); return Redirect::action([self::class, 'index']); @@ -45,10 +39,10 @@ public function create(): RedirectResponse /** * Store a newly created resource in storage. */ + #[Authorize('create-relationship')] public function store(Request $request): RedirectResponse { // relationships are not created directly here; they are created through the person controller // TODO: stub: re-evaluate handling of relationships to refactor person controller to avoid repetition - Gate::authorize('create-relationship'); flash('Relationships cannot be directly stored as they are managed via contacts')->error(); return Redirect::action([self::class, 'index']); @@ -57,9 +51,9 @@ public function store(Request $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-relationship')] public function show(int $id): View { - Gate::authorize('show-relationship'); $relationship = \App\Models\Relationship::findOrFail($id); return view('relationships.show', compact('relationship')); @@ -68,9 +62,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-relationship')] public function edit(int $id): RedirectResponse { // TODO: stub: re-evaluate handling of relationships to refactor person controller to avoid repetition - Gate::authorize('update-relationship'); flash('Relationships cannot be directly edited as they are managed via contacts')->error(); return Redirect::action([self::class, 'show'], $id); @@ -79,9 +73,9 @@ public function edit(int $id): RedirectResponse /** * Update the specified resource in storage. */ + #[Authorize('update-relationship')] public function update(Request $request, int $id): RedirectResponse { // TODO: stub: re-evaluate handling of relationships to refactor person controller to avoid repetition - Gate::authorize('update-relationship'); flash('Relationships cannot be directly updated as they are managed via contacts')->error(); return Redirect::action([self::class, 'show'], $id); @@ -90,10 +84,9 @@ public function update(Request $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-relationship')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-relationship'); - \App\Models\Relationship::destroy($id); flash('Relationship ID#: '.$id.' deleted')->warning()->important(); @@ -101,9 +94,9 @@ public function destroy(int $id): RedirectResponse return redirect()->back(); } + #[Authorize('update-contact')] public function disjoined(): View { - Gate::authorize('update-contact'); $couples = DB::table('relationship as r') ->select('r.id', 'r.contact_id_a as husband_id', 'h.sort_name as husband_name', 'r.contact_id_b as wife_id', 'w.sort_name as wife_name', 'ha.street_address as husband_address', 'ha.city as husband_city', 'ha.postal_code as husband_zip', 'wa.street_address as wife_address', 'wa.city as wife_city', 'wa.postal_code as wife_zip') ->leftJoin('contact as h', 'r.contact_id_a', '=', 'h.id') @@ -125,9 +118,9 @@ public function disjoined(): View return view('relationships.disjoined', compact('couples')); } + #[Authorize('update-contact')] public function rejoin($id, $dominant): RedirectResponse { - Gate::authorize('update-contact'); $relationship = \App\Models\Relationship::with('contact_a.address_primary', 'contact_b.address_primary')->findOrFail($id); switch ($dominant) { case $relationship->contact_id_a: diff --git a/app/Http/Controllers/RelationshipTypeController.php b/app/Http/Controllers/RelationshipTypeController.php index adb30d039..20a3b7783 100644 --- a/app/Http/Controllers/RelationshipTypeController.php +++ b/app/Http/Controllers/RelationshipTypeController.php @@ -8,29 +8,23 @@ use App\Http\Requests\UpdateRelationshipTypeRequest; use App\Traits\SquareSpaceTrait; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Arr; -use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class RelationshipTypeController extends Controller implements HasMiddleware +#[Middleware('auth')] +class RelationshipTypeController extends Controller { use SquareSpaceTrait; - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-relationshiptype')] public function index(): View { - Gate::authorize('show-relationshiptype'); $relationship_types = \App\Models\RelationshipType::whereIsActive(1)->orderBy('description')->get(); return view('relationships.types.index', compact('relationship_types')); // @@ -39,9 +33,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-relationshiptype')] public function create(): View { - Gate::authorize('create-relationshiptype'); $contact_types = \App\Models\ContactType::OrderBy('name')->pluck('name', 'name'); return view('relationships.types.create', compact('contact_types')); @@ -50,10 +44,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-relationshiptype')] public function store(StoreRelationshipTypeRequest $request): RedirectResponse { - Gate::authorize('create-relationshiptype'); - $relationship_type = new \App\Models\RelationshipType; $relationship_type->description = $request->input('description'); $relationship_type->name_a_b = $request->input('name_a_b'); @@ -95,9 +88,9 @@ public function store(StoreRelationshipTypeRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-relationshiptype')] public function show(int $id): View { - Gate::authorize('show-relationshiptype'); $relationship_type = \App\Models\RelationshipType::findOrFail($id); $relationships = \App\Models\Relationship::whereRelationshipTypeId($id)->orderBy('contact_id_a')->with('contact_a', 'contact_b')->paginate(25, ['*'], 'relationships'); @@ -107,9 +100,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-relationshiptype')] public function edit(int $id): View { - Gate::authorize('update-relationshiptype'); $relationship_type = \App\Models\RelationshipType::findOrFail($id); return view('relationships.types.edit', compact('relationship_type')); @@ -118,10 +111,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-relationshiptype')] public function update(UpdateRelationshipTypeRequest $request, int $id): RedirectResponse { - Gate::authorize('update-relationshiptype'); - $relationship_type = \App\Models\RelationshipType::findOrFail($request->input('id')); $relationship_type->description = $request->input('description'); $relationship_type->name_a_b = $request->input('name_a_b'); @@ -141,10 +133,9 @@ public function update(UpdateRelationshipTypeRequest $request, int $id): Redirec /** * Remove the specified resource from storage. */ + #[Authorize('delete-relationshiptype')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-relationshiptype'); - $relationship_type = \App\Models\RelationshipType::findOrFail($id); \App\Models\RelationshipType::destroy($id); @@ -153,9 +144,9 @@ public function destroy(int $id): RedirectResponse return Redirect::action([self::class, 'index']); } + #[Authorize('create-relationship')] public function addme(AddmeRelationshipTypeRequest $request): View { - Gate::authorize('create-relationship'); $relationship_type_name = $request->input('relationship_type_name'); $relationship_filter_alternate_name = ($request->input('relationship_filter_alternate_name') == null) ? null : $request->input('relationship_filter_alternate_name'); $contact_id = $request->input('contact_id'); @@ -254,9 +245,9 @@ public function addme(AddmeRelationshipTypeRequest $request): View return view('relationships.types.add', compact('relationship_type', 'primary_contact', 'contact_list', 'direction')); } + #[Authorize('create-relationship')] public function make(MakeRelationshipTypeRequest $request): RedirectResponse { - Gate::authorize('create-relationship'); // a very hacky way to get the contact_id of the user that we are creating a relationship for // this allows the ability to redirect back to that user $contact_id = ($request->input('direction') == 'a') ? $request->input('contact_a_id') : $request->input('contact_b_id'); @@ -272,9 +263,9 @@ public function make(MakeRelationshipTypeRequest $request): RedirectResponse return redirect()->to($contact->contact_url); } + #[Authorize('show-contact')] public function get_contact_type_list($contact_type = 'Individual', $contact_subtype = null, $contact_id = null, $relationship_filter_alternate_name = null) { - Gate::authorize('show-contact'); // dd($contact_type, $contact_subtype); switch ($contact_type) { case 'Household': diff --git a/app/Http/Controllers/RetreatController.php b/app/Http/Controllers/RetreatController.php index ff3a95bb3..5c812ea33 100644 --- a/app/Http/Controllers/RetreatController.php +++ b/app/Http/Controllers/RetreatController.php @@ -9,29 +9,23 @@ use App\Models\Registration; use Auth; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Arr; -use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; use Spatie\GoogleCalendar\Event; use Storage; -class RetreatController extends Controller implements HasMiddleware +#[Middleware('auth')] +class RetreatController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-retreat')] public function index(): View { - Gate::authorize('show-retreat'); // do once in controller to reduce excessive number of checks on blade $permission_checks = ['show-retreat', 'show-event-contract', 'show-event-schedule', 'show-event-evaluation']; foreach ($permission_checks as $permission_check => $permission) { @@ -48,9 +42,9 @@ public function index(): View return view('retreats.index', compact('retreats', 'oldretreats', 'defaults', 'event_types', 'results')); // } + #[Authorize('show-retreat')] public function index_type($event_type_id): View { - Gate::authorize('show-retreat'); $permission_checks = ['show-retreat', 'show-event-contract', 'show-event-schedule', 'show-event-evaluation']; foreach ($permission_checks as $permission_check => $permission) { $results[$permission] = Auth::user()->can($permission); @@ -69,10 +63,9 @@ public function index_type($event_type_id): View /** * Show the form for creating a new resource. */ + #[Authorize('create-retreat')] public function create(): View { - Gate::authorize('create-retreat'); - $retreat_house = \App\Models\Contact::with('retreat_directors.contact_b', 'retreat_innkeepers.contact_b', 'retreat_assistants.contact_b', 'retreat_ambassadors.contact_b')->findOrFail(config('polanco.self.id')); $event_types = \App\Models\EventType::whereIsActive(1)->orderBy('name')->pluck('name', 'id'); $is_active[0] = 'Canceled'; @@ -122,10 +115,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-retreat')] public function store(StoreRetreatRequest $request): RedirectResponse { - Gate::authorize('create-retreat'); - $retreat = new \App\Models\Retreat; $retreat->idnumber = $request->input('idnumber'); @@ -241,9 +233,9 @@ public function add_participant(int $contact_id, int $event_id, int $participant /** * Display the specified resource. */ + #[Authorize('show-retreat')] public function show(int $id, $status = null): View { - Gate::authorize('show-retreat'); $retreat = \App\Models\Retreat::with('retreatmasters.contact', 'innkeepers.contact', 'assistants.contact', 'ambassadors.contact')->findOrFail($id); $attachments = \App\Models\Attachment::whereEntity('event')->whereEntityId($id)->whereFileTypeId(config('polanco.file_type.event_attachment'))->get(); @@ -344,18 +336,18 @@ public function show(int $id, $status = null): View return view('retreats.show', compact('retreat', 'registrations', 'status', 'attachments')); // } + #[Authorize('show-retreat')] public function show_waitlist($id): View { - Gate::authorize('show-retreat'); $retreat = \App\Models\Retreat::with('retreatmasters.contact', 'innkeepers.contact', 'assistants.contact', 'ambassadors.contact')->findOrFail($id); $registrations = \App\Models\Registration::where('event_id', '=', $id)->whereStatusId(config('polanco.registration_status_id.waitlist'))->with('retreatant.parish')->orderBy('register_date', 'ASC')->get(); return view('retreats.waitlist', compact('retreat', 'registrations')); // } + #[Authorize('show-retreat')] public function get_event_by_id_number($id_number, $status = null) { - Gate::authorize('show-retreat'); $retreat = \App\Models\Retreat::with('retreatmasters.contact', 'innkeepers.contact', 'assistants.contact', 'ambassadors.contact')->whereIdnumber($id_number)->firstOrFail(); return $this->show($retreat->id, $status); @@ -369,9 +361,9 @@ public function get_event_by_id_number($id_number, $status = null) // $retreats = \App\Models\Retreat::(); // return view('retreats.edit',compact('retreats')); // } + #[Authorize('update-retreat')] public function edit(int $id): View { - Gate::authorize('update-retreat'); // get this retreat's information $retreat = \App\Models\Retreat::with('retreatmasters.contact', 'assistants.contact', 'innkeepers.contact', 'ambassadors.contact')->findOrFail($id); $event_types = \App\Models\EventType::whereIsActive(1)->orderBy('name')->pluck('name', 'id'); @@ -458,10 +450,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-retreat')] public function update(UpdateRetreatRequest $request, int $id): RedirectResponse { - Gate::authorize('update-retreat'); - $retreat = \App\Models\Retreat::findOrFail($request->input('id')); $retreat->idnumber = $request->input('idnumber'); $retreat->start_date = $request->input('start_date'); @@ -625,9 +616,9 @@ public function update(UpdateRetreatRequest $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-retreat')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-retreat'); $retreat = \App\Models\Retreat::findOrFail($id); // if there is a calendar id for the event then find the Google Calendar event, mark it as canceled and then remove it from the calendar (soft delete) if (! empty($retreat->calendar_id)) { @@ -648,9 +639,9 @@ public function destroy(int $id): RedirectResponse return Redirect::action([self::class, 'index']); } + #[Authorize('update-registration')] public function assign_rooms($id): View { - Gate::authorize('update-registration'); // get this retreat's information $retreat = \App\Models\Retreat::with('retreatmasters.contact', 'assistants.contact', 'innkeepers.contact', 'ambassadors.contact')->findOrFail($id); $registrations = \App\Models\Registration::where('event_id', '=', $id)->with('retreatant.parish')->orderBy('register_date', 'DESC')->whereStatusId(config('polanco.registration_status_id.registered'))->get(); @@ -660,9 +651,9 @@ public function assign_rooms($id): View return view('retreats.assign_rooms', compact('retreat', 'registrations', 'rooms')); } + #[Authorize('update-payment')] public function edit_payments($id): View { - Gate::authorize('update-payment'); // get this retreat's information $retreat = \App\Models\Retreat::findOrFail($id); $registrations = \App\Models\Registration::where('event_id', '=', $id)->whereCanceledAt(null)->with('retreatant.parish', 'donation')->orderBy('register_date', 'DESC')->get(); @@ -673,20 +664,20 @@ public function edit_payments($id): View return view('retreats.payments.edit', compact('retreat', 'registrations', 'donation_description', 'payment_description')); } + #[Authorize('show-payment')] public function show_payments($id): View { - Gate::authorize('show-payment'); $retreat = \App\Models\Retreat::findOrFail($id); $registrations = \App\Models\Registration::where('event_id', '=', $id)->whereCanceledAt(null)->with('retreatant.parish', 'donation')->orderBy('register_date', 'DESC')->get(); return view('retreats.payments.show', compact('retreat', 'registrations')); } + #[Authorize('update-registration')] public function checkout($id): RedirectResponse { /* checkout all registrations for a retreat where the arrived_at is not NULL and the departed is NULL for a particular event */ // TODO: consider also checking to see if the arrived_at time is empty and if it is put in the retreat start time - Gate::authorize('update-registration'); $retreat = \App\Models\Retreat::findOrFail($id); // verifies that it is a valid retreat id $registrations = \App\Models\Registration::whereEventId($id)->whereCanceledAt(null)->whereDepartedAt(null)->whereNotNull('arrived_at')->get(); foreach ($registrations as $registration) { @@ -699,10 +690,10 @@ public function checkout($id): RedirectResponse return Redirect::action([self::class, 'show'], $retreat->id); } + #[Authorize('update-registration')] public function checkin($id): RedirectResponse { /* checkout all registrations for a retreat where the arrived_at is not NULL and the departed is NULL for a particular event */ - Gate::authorize('update-registration'); $retreat = \App\Models\Retreat::findOrFail($id); // verifies that it is a valid retreat id $registrations = \App\Models\Registration::whereEventId($id)->whereCanceledAt(null)->whereDepartedAt(null)->whereNull('arrived_at')->get(); foreach ($registrations as $registration) { @@ -715,10 +706,9 @@ public function checkin($id): RedirectResponse return Redirect::action([self::class, 'show'], $retreat->id); } + #[Authorize('update-registration')] public function room_update(RoomUpdateRetreatRequest $request): RedirectResponse { - Gate::authorize('update-registration'); - if ($request->input('registrations') !== null) { foreach ($request->input('registrations') as $key => $value) { $registration = \App\Models\Registration::findOrFail($key); @@ -749,9 +739,9 @@ public function room_update(RoomUpdateRetreatRequest $request): RedirectResponse } } + #[Authorize('show-retreat')] public function calendar(): View { - Gate::authorize('show-retreat'); if ($this->is_google_calendar_enabled()) { $calendar_events = \Spatie\GoogleCalendar\Event::get(); } else { @@ -761,6 +751,7 @@ public function calendar(): View return view('calendar.index', compact('calendar_events')); } + #[Authorize('show-registration')] public function event_room_list($event_id): View { // get buildings for which there are assigned rooms @@ -768,7 +759,6 @@ public function event_room_list($event_id): View // for each registration add contact sort_name to room // view room_lists // TODO: write unit tests for this method - Gate::authorize('show-registration'); $event = \App\Models\Retreat::findOrFail($event_id); $registrations = \App\Models\Registration::whereEventId($event_id)->whereNull('canceled_at')->with('room')->get(); $room_ids = \App\Models\Registration::whereEventId($event_id)->whereNull('canceled_at')->pluck('room_id'); @@ -809,11 +799,11 @@ public function event_room_list($event_id): View return view('retreats.roomlist', compact('results', 'event')); } + #[Authorize('show-registration')] public function event_namebadges($event_id, $role = null): View { // for each registration add contact sort_name to namebadge // TODO: write unit tests for this method - Gate::authorize('show-registration'); $event = \App\Models\Retreat::findOrFail($event_id); switch ($role) { case 'retreatant': $role = config('polanco.participant_role_id.retreatant'); @@ -862,11 +852,11 @@ public function event_namebadges($event_id, $role = null): View return view('retreats.namebadges', compact('cresults', 'event')); } + #[Authorize('show-registration')] public function event_tableplacards($event_id): View { // for each registration add contact sort_name to namebadge // TODO: write unit tests for this method - Gate::authorize('show-registration'); $event = \App\Models\Retreat::findOrFail($event_id); $registrations = \App\Models\Registration::whereEventId($event_id)->whereNull('canceled_at')->whereStatusId(config('polanco.registration_status_id.registered'))->get(); @@ -894,19 +884,18 @@ public function event_tableplacards($event_id): View return view('retreats.tableplacards', compact('cresults', 'event')); } + #[Authorize('show-retreat')] public function search(): View { - Gate::authorize('show-retreat'); $event_types = \App\Models\EventType::whereIsActive(true)->orderBy('label')->pluck('label', 'id'); $event_types->prepend('N/A', ''); return view('retreats.search', compact('event_types')); } + #[Authorize('show-retreat')] public function results(EventSearchRequest $request): View { - Gate::authorize('show-retreat'); - if (! empty($request)) { $events = \App\Models\Retreat::filtered($request)->orderBy('idnumber')->paginate(25, ['*'], 'events'); $events->appends($request->except('page')); diff --git a/app/Http/Controllers/RoleController.php b/app/Http/Controllers/RoleController.php index 27e521072..ec3e39976 100644 --- a/app/Http/Controllers/RoleController.php +++ b/app/Http/Controllers/RoleController.php @@ -4,23 +4,17 @@ use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class RoleController extends Controller implements HasMiddleware +#[Middleware('auth')] +class RoleController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-role')] public function index(): View { - Gate::authorize('show-role'); $roles = \App\Models\Role::orderBy('name')->get(); return view('admin.roles.index', compact('roles')); @@ -29,20 +23,18 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-role')] public function create(): View { - Gate::authorize('create-role'); - return view('admin.roles.create'); } /** * Store a newly created resource in storage. */ + #[Authorize('create-role')] public function store(Request $request): RedirectResponse { - Gate::authorize('create-role'); - $role = new \App\Models\Role; $role->name = $request->input('name'); $role->display_name = $request->input('display_name'); @@ -58,10 +50,9 @@ public function store(Request $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-role')] public function show(int $id): View { - Gate::authorize('show-role'); - $role = \App\Models\Role::with('users', 'permissions')->findOrFail($id); $permissions = \App\Models\Permission::orderBy('name')->pluck('name', 'id'); $users = \App\Models\User::orderBy('name')->pluck('name', 'id'); @@ -72,10 +63,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-role')] public function edit(int $id): View { - Gate::authorize('update-role'); - $role = \App\Models\Role::findOrFail($id); return view('admin.roles.edit', compact('role')); // @@ -84,10 +74,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-role')] public function update(Request $request, int $id): RedirectResponse { - Gate::authorize('update-role'); - $role = \App\Models\Role::findOrFail($request->input('id')); $role->name = $request->input('name'); $role->display_name = $request->input('display_name'); @@ -102,10 +91,9 @@ public function update(Request $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-role')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-role'); - $role = \App\Models\Role::findOrFail($id); \App\Models\Role::destroy($id); @@ -114,9 +102,9 @@ public function destroy(int $id): RedirectResponse return Redirect::action([self::class, 'index']); } + #[Authorize('update-role')] public function update_permissions(Request $request): RedirectResponse { - Gate::authorize('update-role'); $role = \App\Models\Role::findOrFail($request->input('id')); $role->permissions()->detach(); $role->permissions()->sync($request->input('permissions')); @@ -126,9 +114,9 @@ public function update_permissions(Request $request): RedirectResponse return Redirect::action([self::class, 'index']); } + #[Authorize('update-role')] public function update_users(Request $request): RedirectResponse { - Gate::authorize('update-role'); $role = \App\Models\Role::findOrFail($request->input('id')); $role->users()->detach(); $role->users()->sync($request->input('users')); diff --git a/app/Http/Controllers/RoomController.php b/app/Http/Controllers/RoomController.php index 23c09112e..3069d1261 100644 --- a/app/Http/Controllers/RoomController.php +++ b/app/Http/Controllers/RoomController.php @@ -7,28 +7,22 @@ use Carbon\Carbon; use DateTime; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class RoomController extends Controller implements HasMiddleware +#[Middleware('auth')] +class RoomController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ + #[Authorize('show-room')] public function index() { - Gate::authorize('show-room'); // TODO: consider eager loading building name and sorting on room.location.name $rooms = \App\Models\Room::with('location')->get(); $roomsort = $rooms->sortBy(function ($building) { @@ -41,9 +35,9 @@ public function index() /** * Show the form for creating a new resource. */ + #[Authorize('create-room')] public function create(): View { - Gate::authorize('create-room'); $locations = \App\Models\Location::orderby('name')->pluck('name', 'id'); $floors = $this->get_floors(); @@ -53,10 +47,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-room')] public function store(StoreRoomRequest $request): RedirectResponse { - Gate::authorize('create-room'); - $room = new \App\Models\Room; $room->location_id = $request->input('location_id'); $room->name = $request->input('name'); @@ -77,9 +70,9 @@ public function store(StoreRoomRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-room')] public function show(int $id): View { - Gate::authorize('show-room'); $room = \App\Models\Room::findOrFail($id); $building = \App\Models\Room::findOrFail($id)->location; $room->building = $building->name; @@ -90,9 +83,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-room')] public function edit(int $id): View { - Gate::authorize('update-room'); $locations = \App\Models\Location::orderby('name')->pluck('name', 'id'); $floors = $this->get_floors(); $room = \App\Models\Room::findOrFail($id); @@ -103,10 +96,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-room')] public function update(UpdateRoomRequest $request, int $id): RedirectResponse { - Gate::authorize('update-room'); - $room = \App\Models\Room::findOrFail($request->input('id')); $room->location_id = $request->input('location_id'); $room->name = $request->input('name'); @@ -127,9 +119,9 @@ public function update(UpdateRoomRequest $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-room')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-room'); $room = \App\Models\Room::findOrFail($id); \App\Models\Room::destroy($id); @@ -161,9 +153,9 @@ public function get_floors() * * @return \Illuminate\Http\Response */ + #[Authorize('show-room')] public function schedule(int|string|null $ymd = null) { - Gate::authorize('show-room'); if ((! isset($ymd)) or ($ymd == 0)) { $dt = Carbon::now(); } else { diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 343b34609..69c73545f 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -6,23 +6,17 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\View\View; -class SearchController extends Controller implements HasMiddleware +#[Middleware('auth')] +class SearchController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-contact')] public function autocomplete(Request $request): JsonResponse { - Gate::authorize('show-contact'); - $term = $request->get('term'); + $term = $request->input('term'); $results = []; $queries = \App\Models\Contact::orderBy('sort_name')->where('display_name', 'LIKE', '%'.$term.'%')->whereDeletedAt(null)->take(20)->get(); if (($queries->count() == 0)) { @@ -35,13 +29,13 @@ public function autocomplete(Request $request): JsonResponse return response()->json($results); } + #[Authorize('show-contact')] public function getuser(Request $request): RedirectResponse { // dd($request); - Gate::authorize('show-contact'); - if (empty($request->get('response'))) { + if (empty($request->input('response'))) { $id = 0; } else { - $id = $request->get('response'); + $id = $request->input('response'); } if ($id == 0) { @@ -54,9 +48,9 @@ public function getuser(Request $request): RedirectResponse } } + #[Authorize('show-contact')] public function results(SearchRequest $request): View { - Gate::authorize('show-contact'); if (! empty($request)) { $persons = \App\Models\Contact::filtered($request)->orderBy('sort_name')->with('attachments')->paginate(25, ['*'], 'persons'); $persons->appends($request->except('page')); @@ -68,10 +62,9 @@ public function results(SearchRequest $request): View return view('search.results', compact('persons')); } + #[Authorize('show-contact')] public function search(): View { - Gate::authorize('show-contact'); - $contact_types = \App\Models\ContactType::whereIsReserved(true)->pluck('label', 'id'); $contact_types->prepend('N/A', ''); diff --git a/app/Http/Controllers/SnippetController.php b/app/Http/Controllers/SnippetController.php index 912f488d5..32ba72fb7 100644 --- a/app/Http/Controllers/SnippetController.php +++ b/app/Http/Controllers/SnippetController.php @@ -11,36 +11,28 @@ use Auth; use Faker; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Storage; use Illuminate\View\View; -class SnippetController extends Controller implements HasMiddleware +#[Middleware('auth')] +class SnippetController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-snippet')] public function index(): View { - Gate::authorize('show-snippet'); - $titles = \App\Models\Snippet::groupBy('title')->with('language')->orderBy('title')->pluck('title', 'title'); $snippets = \App\Models\Snippet::orderBy('title')->with('language')->orderBy('locale')->orderBy('label')->get(); return view('admin.snippets.index', compact('snippets', 'titles')); } + #[Authorize('show-snippet')] public function index_type($title = null): View { - Gate::authorize('show-snippet'); - $titles = \App\Models\Snippet::groupBy('title')->with('language')->orderBy('title')->pluck('title', 'title'); $snippets = \App\Models\Snippet::whereTitle($title)->with('language')->orderBy('title')->orderBy('locale')->orderBy('label')->get(); @@ -50,9 +42,9 @@ public function index_type($title = null): View /** * Show the form for creating a new resource. */ + #[Authorize('create-snippet')] public function create(): View { - Gate::authorize('create-snippet'); $locales = \App\Models\Language::whereIsActive(1)->orderBy('label')->pluck('label', 'name'); return view('admin.snippets.create', compact('locales')); @@ -61,10 +53,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-snippet')] public function store(StoreSnippetRequest $request): RedirectResponse { - Gate::authorize('create-snippet'); - $snippet = new \App\Models\Snippet; $snippet->title = $request->input('title'); $snippet->label = $request->input('label'); @@ -81,10 +72,9 @@ public function store(StoreSnippetRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-snippet')] public function show(int $id): View { - Gate::authorize('show-snippet'); - $snippet = \App\Models\Snippet::findOrFail($id); return view('admin.snippets.show', compact('snippet')); @@ -93,10 +83,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-snippet')] public function edit(int $id): View { - Gate::authorize('update-snippet'); - $snippet = \App\Models\Snippet::findOrFail($id); $locales = \App\Models\Language::whereIsActive(1)->orderBy('label')->pluck('label', 'name'); @@ -106,10 +95,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-snippet')] public function update(UpdateSnippetRequest $request, int $id): RedirectResponse { - Gate::authorize('update-snippet'); - $snippet = \App\Models\Snippet::findOrFail($id); $snippet->title = $request->input('title'); @@ -127,9 +115,9 @@ public function update(UpdateSnippetRequest $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-snippet')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-snippet'); $snippet = \App\Models\Snippet::findOrFail($id); \App\Models\Snippet::destroy($id); @@ -139,10 +127,9 @@ public function destroy(int $id): RedirectResponse return Redirect::action([self::class, 'index']); } + #[Authorize('show-snippet')] public function snippet_test(SnippetTestRequest $request): RedirectResponse { - Gate::authorize('show-snippet'); - $title = $request->input('title'); $email = $request->input('email'); $language = $request->input('language'); @@ -274,9 +261,9 @@ public function snippet_test(SnippetTestRequest $request): RedirectResponse /** * Show the form for creating a new resource. */ + #[Authorize('show-snippet')] public function test($title = null, $email = null, $language = 'en_US'): View { - Gate::authorize('show-snippet'); $titles = \App\Models\Snippet::groupBy('title')->orderBy('title')->pluck('title', 'title'); $languages = \App\Models\Language::whereIsActive(1)->orderBy('label')->pluck('label', 'name'); if (empty($email)) { diff --git a/app/Http/Controllers/SquarespaceContributionController.php b/app/Http/Controllers/SquarespaceContributionController.php index b8e35fc08..622424086 100644 --- a/app/Http/Controllers/SquarespaceContributionController.php +++ b/app/Http/Controllers/SquarespaceContributionController.php @@ -19,29 +19,23 @@ use Carbon\Carbon; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Str; use Illuminate\View\View; -class SquarespaceContributionController extends Controller implements HasMiddleware +#[Middleware('auth')] +class SquarespaceContributionController extends Controller { use SquareSpaceTrait; - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-squarespace-contribution')] public function index(): View { - Gate::authorize('show-squarespace-contribution'); $ss_contributions = SquarespaceContribution::whereIsProcessed(0)->orderBy('created_at')->paginate(25, ['*'], 'ss_contributions'); $processed_ss_contributions = SquarespaceContribution::whereIsProcessed(1)->orderByDesc('created_at')->paginate(25, ['*'], 'ss_unprocessed_contributions'); @@ -51,31 +45,29 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('show-squarespace-contribution')] public function create(): RedirectResponse { // use permisson of target, namely squarespace.contribution.index - Gate::authorize('show-squarespace-contribution'); - return Redirect::action([self::class, 'index']); } /** * Store a newly created resource in storage. */ + #[Authorize('show-squarespace-contribution')] public function store(Request $request): RedirectResponse { // use permisson of target, namely squarespace.contribution.index - Gate::authorize('show-squarespace-contribution'); - return Redirect::action([self::class, 'index']); } /** * Display the specified resource. */ + #[Authorize('show-squarespace-contribution')] public function show(int $id): View { - Gate::authorize('show-squarespace-contribution'); $ss_contribution = SquarespaceContribution::findOrFail($id); return view('squarespace.contribution.show', compact('ss_contribution')); @@ -84,10 +76,9 @@ public function show(int $id): View /** * Show a contribution to confirm the retreatant for a SquareSpace order. */ + #[Authorize('update-squarespace-contribution')] public function edit(int $id): View { - Gate::authorize('update-squarespace-contribution'); - $ss_contribution = SquarespaceContribution::findOrFail($id); $descriptions = DonationType::active()->orderby('name')->pluck('name', 'name'); @@ -287,21 +278,19 @@ public function update(UpdateSquarespaceContributionRequest $request, int $id): /** * Remove the specified resource from storage. */ + #[Authorize('show-squarespace-contribution')] public function destroy(int $id): RedirectResponse { // use permisson of target, namely squarespace.contribution.index - Gate::authorize('show-squarespace-contribution'); - return Redirect::action([self::class, 'index']); } /** * Reset to re-select the retreatant for a SquareSpace contribution. */ + #[Authorize('update-squarespace-contribution')] public function reset(int $id): RedirectResponse { - Gate::authorize('update-squarespace-contribution'); - $ss_contribution = SquarespaceContribution::findOrFail($id); $ss_contribution->contact_id = null; $ss_contribution->save(); diff --git a/app/Http/Controllers/SquarespaceController.php b/app/Http/Controllers/SquarespaceController.php index 4e1f78664..8164353b6 100644 --- a/app/Http/Controllers/SquarespaceController.php +++ b/app/Http/Controllers/SquarespaceController.php @@ -3,46 +3,37 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\View\View; -class SquarespaceController extends Controller implements HasMiddleware +#[Middleware('auth')] +class SquarespaceController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-squarespace')] public function index(): View { - Gate::authorize('show-squarespace'); - return view('squarespace.index'); } /** * Display a listing of the resource. */ + #[Authorize('show-squarespace')] public function contribution_index(): View { - Gate::authorize('show-squarespace'); - return view('squarespace.contribution'); } /** * Display a listing of the resource. */ + #[Authorize('show-squarespace')] public function order_index(): View { - Gate::authorize('show-squarespace'); - return view('squarespace.order'); } diff --git a/app/Http/Controllers/SquarespaceCustomFormController.php b/app/Http/Controllers/SquarespaceCustomFormController.php index bc28392fa..9261ecfdc 100644 --- a/app/Http/Controllers/SquarespaceCustomFormController.php +++ b/app/Http/Controllers/SquarespaceCustomFormController.php @@ -7,27 +7,20 @@ use App\Http\Requests\UpdateSquarespaceCustomFormFieldRequest; use App\Http\Requests\UpdateSquarespaceCustomFormRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class SquarespaceCustomFormController extends Controller implements HasMiddleware +#[Middleware('auth')] +class SquarespaceCustomFormController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-squarespace-custom-form')] public function index(): View { - Gate::authorize('show-squarespace-custom-form'); - $custom_forms = \App\Models\SquarespaceCustomForm::orderBy('name')->with('fields')->get(); return view('admin.squarespace.custom_forms.index', compact('custom_forms')); @@ -36,19 +29,18 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-squarespace-custom-form')] public function create(): View { - Gate::authorize('create-squarespace-custom-form'); - return view('admin.squarespace.custom_forms.create'); } /** * Show the form for creating a new resource. */ + #[Authorize('create-squarespace-custom-form')] public function create_field($id): View { - Gate::authorize('create-squarespace-custom-form'); $custom_form = \App\Models\SquarespaceCustomForm::findOrFail($id); return view('admin.squarespace.custom_forms.fields.create', compact(['custom_form'])); @@ -57,10 +49,9 @@ public function create_field($id): View /** * Store a newly created resource in storage. */ + #[Authorize('create-squarespace-custom-form')] public function store(StoreSquarespaceCustomFormRequest $request): RedirectResponse { - Gate::authorize('create-squarespace-custom-form'); - $custom_form = new \App\Models\SquarespaceCustomForm; $custom_form->name = $request->input('name'); $custom_form->save(); @@ -73,9 +64,9 @@ public function store(StoreSquarespaceCustomFormRequest $request): RedirectRespo /** * Store a newly created custom form field in storage. */ + #[Authorize('create-squarespace-custom-form')] public function store_field(StoreSquarespaceCustomFormFieldRequest $request): RedirectResponse { - Gate::authorize('create-squarespace-custom-form'); $id = $request->input('id'); $custom_form = \App\Models\SquarespaceCustomForm::findOrFail($id); $custom_form_field = new \App\Models\SquarespaceCustomFormField; @@ -94,10 +85,9 @@ public function store_field(StoreSquarespaceCustomFormFieldRequest $request): Re /** * Display the specified resource. */ + #[Authorize('show-squarespace-custom-form')] public function show(int $id): View { - Gate::authorize('show-squarespace-custom-form'); - $custom_form = \App\Models\SquarespaceCustomForm::with('fields')->findOrFail($id); return view('admin.squarespace.custom_forms.show', compact('custom_form')); @@ -106,10 +96,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-squarespace-custom-form')] public function edit(int $id): View { - Gate::authorize('update-squarespace-custom-form'); - $custom_form = \App\Models\SquarespaceCustomForm::with('fields')->findOrFail($id); return view('admin.squarespace.custom_forms.edit', compact('custom_form')); // @@ -118,10 +107,9 @@ public function edit(int $id): View /** * Show the form for editing custom form field. */ + #[Authorize('update-squarespace-custom-form')] public function edit_field(int $id): View { - Gate::authorize('update-squarespace-custom-form'); - $custom_form_field = \App\Models\SquarespaceCustomFormField::with('form')->findOrFail($id); return view('admin.squarespace.custom_forms.fields.edit', compact('custom_form_field')); // @@ -130,10 +118,9 @@ public function edit_field(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-squarespace-custom-form')] public function update(UpdateSquarespaceCustomFormRequest $request, int $id): RedirectResponse { - Gate::authorize('update-squarespace-custom-form'); - $custom_form = \App\Models\SquarespaceCustomForm::findOrFail($id); $custom_form->name = $request->input('name'); @@ -149,10 +136,9 @@ public function update(UpdateSquarespaceCustomFormRequest $request, int $id): Re * * @param int $id */ + #[Authorize('update-squarespace-custom-form')] public function update_field(UpdateSquarespaceCustomFormFieldRequest $request): RedirectResponse { - Gate::authorize('update-squarespace-custom-form'); - $custom_form_field = \App\Models\SquarespaceCustomFormField::findOrFail($request->input('id')); $custom_form_field->name = $request->input('name'); @@ -169,9 +155,9 @@ public function update_field(UpdateSquarespaceCustomFormFieldRequest $request): /** * Remove the specified resource from storage. */ + #[Authorize('delete-squarespace-custom-form')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-squarespace-custom-form'); $custom_form = \App\Models\SquarespaceCustomForm::findOrFail($id); \App\Models\SquarespaceCustomForm::destroy($id); diff --git a/app/Http/Controllers/SquarespaceInventoryController.php b/app/Http/Controllers/SquarespaceInventoryController.php index b5c729dbb..dab8f3f23 100644 --- a/app/Http/Controllers/SquarespaceInventoryController.php +++ b/app/Http/Controllers/SquarespaceInventoryController.php @@ -5,27 +5,20 @@ use App\Http\Requests\StoreSquarespaceInventoryRequest; use App\Http\Requests\UpdateSquarespaceInventoryRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class SquarespaceInventoryController extends Controller implements HasMiddleware +#[Middleware('auth')] +class SquarespaceInventoryController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-squarespace-inventory')] public function index(): View { - Gate::authorize('show-squarespace-inventory'); - $inventory_items = \App\Models\SquarespaceInventory::orderBy('name')->with('custom_form')->get(); return view('admin.squarespace.inventory.index', compact('inventory_items')); @@ -34,9 +27,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-squarespace-inventory')] public function create(): View { - Gate::authorize('create-squarespace-inventory'); $custom_forms = \App\Models\SquarespaceCustomForm::orderBy('name')->pluck('name', 'id'); return view('admin.squarespace.inventory.create', compact(['custom_forms'])); @@ -45,10 +38,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-squarespace-inventory')] public function store(StoreSquarespaceInventoryRequest $request): RedirectResponse { - Gate::authorize('create-squarespace-inventory'); - $inventory = new \App\Models\SquarespaceInventory; $inventory->name = $request->input('name'); $inventory->custom_form_id = $request->input('custom_form_id'); @@ -63,10 +55,9 @@ public function store(StoreSquarespaceInventoryRequest $request): RedirectRespon /** * Display the specified resource. */ + #[Authorize('show-squarespace-inventory')] public function show(int $id): View { - Gate::authorize('show-squarespace-inventory'); - $inventory = \App\Models\SquarespaceInventory::with('custom_form')->findOrFail($id); return view('admin.squarespace.inventory.show', compact('inventory')); @@ -75,10 +66,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-squarespace-inventory')] public function edit(int $id): View { - Gate::authorize('update-squarespace-inventory'); - $inventory = \App\Models\SquarespaceInventory::findOrFail($id); $custom_forms = \App\Models\SquarespaceCustomForm::orderBy('name')->pluck('name', 'id'); @@ -88,10 +78,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-squarespace-inventory')] public function update(UpdateSquarespaceInventoryRequest $request, int $id): RedirectResponse { - Gate::authorize('update-squarespace-inventory'); - $inventory = \App\Models\SquarespaceInventory::findOrFail($id); $inventory->name = $request->input('name'); @@ -107,9 +96,9 @@ public function update(UpdateSquarespaceInventoryRequest $request, int $id): Red /** * Remove the specified resource from storage. */ + #[Authorize('delete-squarespace-inventory')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-squarespace-inventory'); $inventory = \App\Models\SquarespaceInventory::findOrFail($id); \App\Models\SquarespaceInventory::destroy($id); diff --git a/app/Http/Controllers/SquarespaceOrderController.php b/app/Http/Controllers/SquarespaceOrderController.php index ba098c196..19e7f27c1 100644 --- a/app/Http/Controllers/SquarespaceOrderController.php +++ b/app/Http/Controllers/SquarespaceOrderController.php @@ -28,30 +28,24 @@ use Carbon\Carbon; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Str; use Illuminate\View\View; -class SquarespaceOrderController extends Controller implements HasMiddleware +#[Middleware('auth')] +class SquarespaceOrderController extends Controller { use SquareSpaceTrait; - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-squarespace-order')] public function index(): View { - Gate::authorize('show-squarespace-order'); $unprocessed_orders = SquarespaceOrder::whereIsProcessed(0)->orderBy('order_number')->paginate(25, ['*'], 'unprocessed_orders'); $processed_orders = SquarespaceOrder::whereIsProcessed(1)->orderByDesc('order_number')->paginate(25, ['*'], 'processed_orders'); @@ -62,11 +56,10 @@ public function index(): View * Squarespace orders are created from parsed Mailgun messages * Hence, the create method is an empty slug */ + #[Authorize('show-squarespace-order')] public function create(): RedirectResponse { // use permisson of target, namely squarespace.order.index - Gate::authorize('show-squarespace-order'); - return Redirect::action([self::class, 'index']); } @@ -74,20 +67,19 @@ public function create(): RedirectResponse * Squarespace orders are created from parsed Mailgun messages * Hence, the store method is an empty slug */ + #[Authorize('show-squarespace-order')] public function store(Request $request): RedirectResponse { // use permisson of target, namely squarespace.order.index - Gate::authorize('show-squarespace-order'); - return Redirect::action([self::class, 'index']); } /** * Display the specified resource. */ + #[Authorize('show-squarespace-order')] public function show(int $id): View { - Gate::authorize('show-squarespace-order'); $order = SquarespaceOrder::findOrFail($id); return view('squarespace.order.show', compact('order')); @@ -98,9 +90,9 @@ public function show(int $id): View * * @param int $id */ + #[Authorize('show-squarespace-order')] public function show_order_number($order_number): View { - Gate::authorize('show-squarespace-order'); $order = SquarespaceOrder::whereOrderNumber($order_number)->first(); return view('squarespace.order.show', compact('order')); @@ -109,9 +101,9 @@ public function show_order_number($order_number): View /** * Show an order to confirm the retreatant for a SquareSpace order. */ + #[Authorize('update-squarespace-order')] public function edit(int $id): View { - Gate::authorize('update-squarespace-order'); $order = SquarespaceOrder::findOrFail($id); $gift_certificate = (empty($order->gift_certificate_id)) ? null : GiftCertificate::findOrFail($order->gift_certificate_id); $prefixes = Prefix::orderBy('name')->pluck('name', 'id'); @@ -728,21 +720,19 @@ public function update(UpdateSquarespaceOrderRequest $request, int $id): Redirec /** * Remove the specified resource from storage. */ + #[Authorize('show-squarespace-order')] public function destroy(int $id): RedirectResponse { // use permisson of target, namely squarespace.order.index - Gate::authorize('show-squarespace-order'); - return Redirect::action([self::class, 'index']); } /** * Reset to re-select the retreatant for a SquareSpace order. */ + #[Authorize('update-squarespace-order')] public function reset(int $id): RedirectResponse { - Gate::authorize('update-squarespace-order'); - $order = SquarespaceOrder::findOrFail($id); $order->contact_id = null; $order->save(); diff --git a/app/Http/Controllers/StripeBalanceTransactionController.php b/app/Http/Controllers/StripeBalanceTransactionController.php index 3ec0a2fcc..479eb0fbc 100644 --- a/app/Http/Controllers/StripeBalanceTransactionController.php +++ b/app/Http/Controllers/StripeBalanceTransactionController.php @@ -15,30 +15,23 @@ use Carbon\Carbon; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; use Stripe\StripeClient; -class StripeBalanceTransactionController extends Controller implements HasMiddleware +#[Middleware('auth')] +class StripeBalanceTransactionController extends Controller { use SquareSpaceTrait; - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-stripe-balance-transaction')] public function index(): View { - Gate::authorize('show-stripe-balance-transaction'); - $processed_balance_transactions = StripeBalanceTransaction::whereNotNull('reconcile_date')->orderBy('created_at')->paginate(25, ['*'], 'processed_balance_transactions'); $unprocessed_balance_transactions = StripeBalanceTransaction::whereNull('reconcile_date')->orderByDesc('created_at')->paginate(25, ['*'], 'unprocessed_balance_transactions'); @@ -50,9 +43,9 @@ public function index(): View * * @return \Illuminate\Http\Response */ + #[Authorize('create-stripe-balance-transaction')] public function create() { - Gate::authorize('create-stripe-balance-transaction'); // unused empty shell - records are imported from stripe payouts } @@ -61,20 +54,18 @@ public function create() * * @return \Illuminate\Http\Response */ + #[Authorize('create-stripe-balance-transaction')] public function store(Request $request) { - Gate::authorize('create-stripe-balance-transaction'); - // unused empty shell - balance transactions are imported from stripe payouts } /** * Display the specified resource. */ + #[Authorize('show-stripe-balance-transaction')] public function show($stripe_balance_transaction_id): View { - Gate::authorize('show-stripe-balance-transaction'); - $balance_transaction = StripeBalanceTransaction::whereBalanceTransactionId($stripe_balance_transaction_id)->with('payments')->first(); // dd($balance_transaction); @@ -87,10 +78,9 @@ public function show($stripe_balance_transaction_id): View /** * Display the specified resource. */ + #[Authorize('show-stripe-balance-transaction')] public function show_id(int $id): View { - Gate::authorize('show-stripe-balance-transaction'); - $balance_transaction = StripeBalanceTransaction::with('payments')->findOrFail($id); // dd($balance_transaction); @@ -105,9 +95,9 @@ public function show_id(int $id): View * * @return \Illuminate\Http\Response */ + #[Authorize('update-stripe-balance-transaction')] public function edit(int $id) { - Gate::authorize('update-stripe-balance-transaction'); $unprocessed_squarespace_contributions = collect(); $donations = collect(); // TODO: determine type of transaction order, donation, manual @@ -266,10 +256,9 @@ public function edit(int $id) * * @return \Illuminate\Http\Response */ + #[Authorize('update-stripe-balance-transaction')] public function update(UpdateStripeBalanceTransactionRequest $request, int $id) { - Gate::authorize('update-stripe-balance-transaction'); - $balance_transaction = StripeBalanceTransaction::findOrFail($id); switch ($balance_transaction->transaction_type) { @@ -505,9 +494,9 @@ public function destroy(int $id) /** * Import Stripe Balance Transactions for a given Stripe Payouts into stripe_balance_transaction table */ + #[Authorize('import-stripe-balance_transaction')] public function import($payout_id): RedirectResponse { - Gate::authorize('import-stripe-balance_transaction'); $payout = StripePayout::findOrFail($payout_id); $stripe = new StripeClient(config('services.stripe.secret')); @@ -532,10 +521,9 @@ public function import($payout_id): RedirectResponse return Redirect::action([\App\Http\Controllers\StripePayoutController::class, 'show'], $payout->payout_id); } + #[Authorize('import-stripe-balance_transaction')] public function store_balance_transactions($payout, $stripe_balance_transactions) { - Gate::authorize('import-stripe-balance_transaction'); - $stripe = new StripeClient(config('services.stripe.secret')); foreach ($stripe_balance_transactions->autoPagingIterator() as $stripe_balance_transaction) { $balance_transaction = StripeBalanceTransaction::firstOrNew([ @@ -615,10 +603,9 @@ public function store_balance_transactions($payout, $stripe_balance_transactions /** * Reset to re-select the donor for a Stripe Balance Transaction. */ + #[Authorize('update-stripe-balance-transaction')] public function reset(int $id): RedirectResponse { - Gate::authorize('update-stripe-balance-transaction'); - $balance_transaction = StripeBalanceTransaction::findOrFail($id); $balance_transaction->contact_id = null; $balance_transaction->save(); diff --git a/app/Http/Controllers/StripeChargeController.php b/app/Http/Controllers/StripeChargeController.php index dcefcb8aa..8f1c00e8c 100644 --- a/app/Http/Controllers/StripeChargeController.php +++ b/app/Http/Controllers/StripeChargeController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; use Illuminate\View\View; class StripeChargeController extends Controller @@ -11,10 +11,9 @@ class StripeChargeController extends Controller /** * Display a listing of the resource. */ + #[Authorize('show-stripe-charge')] public function index(): View { - Gate::authorize('show-stripe-charge'); - $stripe = new \Stripe\StripeClient(config('services.stripe.secret')); $charges = $stripe->charges->all([]); @@ -47,10 +46,9 @@ public function store(Request $request) * * @param int $id */ + #[Authorize('show-stripe-charge')] public function show($charge_id): View { - Gate::authorize('show-stripe-charge'); - $stripe = new \Stripe\StripeClient(config('services.stripe.secret')); $charge = $stripe->charges->retrieve($charge_id, []); // $invoice = $stripe->invoices->retrieve($charge->invoice,[]); @@ -94,9 +92,9 @@ public function destroy(int $id) * * @return \Illuminate\Http\Response */ + #[Authorize('import-stripe-charge')] public function import(int $id) { - Gate::authorize('import-stripe-charge'); $stripe = new \Stripe\StripeClient(config('services.stripe.secret')); $charges = $stripe->charges->all([]); foreach ($charges->autoPagingIterator() as $charge) { diff --git a/app/Http/Controllers/StripePayoutController.php b/app/Http/Controllers/StripePayoutController.php index f6ac83477..01819ff07 100644 --- a/app/Http/Controllers/StripePayoutController.php +++ b/app/Http/Controllers/StripePayoutController.php @@ -8,28 +8,21 @@ use Carbon\Carbon; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; use Stripe\StripeClient; -class StripePayoutController extends Controller implements HasMiddleware +#[Middleware('auth')] +class StripePayoutController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-stripe-payout')] public function index(): View { - Gate::authorize('show-stripe-payout'); - $stripe = new StripeClient(config('services.stripe.secret')); $payouts = StripePayout::with('transactions')->orderByDesc('date')->paginate(25, ['*'], 'payouts'); @@ -86,10 +79,9 @@ public function store(Request $request) * * @param int $id */ + #[Authorize('show-stripe-payout')] public function show($payout_id): View { - Gate::authorize('show-stripe-payout'); - $stripe = new StripeClient(config('services.stripe.secret')); $stripe_payout = $stripe->payouts->retrieve($payout_id, []); $stripe_balance_transactions = $stripe->balanceTransactions->all( @@ -130,9 +122,9 @@ public function show($payout_id): View * * @param int $id */ + #[Authorize('show-stripe-payout')] public function show_date($date = null) { - Gate::authorize('show-stripe-payout'); $payout_date = \Carbon\Carbon::parse($date); if (empty($payout_date)) { return redirect()->back(); @@ -177,10 +169,9 @@ public function edit(int $id) /** * Create Stripe Fee donation/payment for a payout. */ + #[Authorize('update-stripe-payout')] public function process_fees(?int $id = null): RedirectResponse { - Gate::authorize('update-stripe-payout'); - $stripe_vendor_id = config('polanco.contact.stripe'); $payout = StripePayout::findOrFail($id); $donation = new \App\Models\Donation; @@ -226,9 +217,9 @@ public function destroy(int $id) /** * Import Stripe Payouts into stripe_payout table */ + #[Authorize('import-stripe-payout')] public function import(): RedirectResponse { - Gate::authorize('import-stripe-payout'); // dd('Stripe Payout Import'); $latest_payout = StripePayout::orderByDesc('date')->first(); $stripe = new StripeClient(config('services.stripe.secret')); @@ -267,9 +258,9 @@ public function import(): RedirectResponse /** * Process Stripe Payout into stripe_charge table */ + #[Authorize('import-stripe-payout')] public function process($id): RedirectResponse { - Gate::authorize('import-stripe-payout'); // dd('Stripe Payout Import'); $stripe = new StripeClient(config('services.stripe.secret')); $payouts = $stripe->payouts->all([]); diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php index 330f7498d..3b6134029 100644 --- a/app/Http/Controllers/SystemController.php +++ b/app/Http/Controllers/SystemController.php @@ -2,19 +2,13 @@ namespace App\Http\Controllers; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\View\View; -class SystemController extends Controller implements HasMiddleware +#[Middleware('auth')] +class SystemController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. * @@ -28,10 +22,9 @@ public function index() /** * Displays phpinfo. */ + #[Authorize('show-admin-menu')] public function phpinfo(): View { - Gate::authorize('show-admin-menu'); - return view('admin.config.phpinfo'); } @@ -62,19 +55,18 @@ public static function is_mailgun_enabled() } } + #[Authorize('show-offeringdedup')] public function offeringdedup_index(): View { - Gate::authorize('show-offeringdedup'); - $offeringdedup = \App\Models\TmpOfferingDedup::orderBy('count', 'desc')->paginate(50); // dd($dioceses); return view('offeringdedup.index', compact('offeringdedup')); } + #[Authorize('show-offeringdedup')] public function offeringdedup_show($contact_id = null, $event_id = null): View { - Gate::authorize('show-offeringdedup'); $donations = \App\Models\Donation::whereEventId($event_id)->whereContactId($contact_id)->whereDonationDescription('Retreat Funding')->get(); $combo = $contact_id.'-'.$event_id; diff --git a/app/Http/Controllers/TouchpointController.php b/app/Http/Controllers/TouchpointController.php index af96d6d0c..932759e30 100644 --- a/app/Http/Controllers/TouchpointController.php +++ b/app/Http/Controllers/TouchpointController.php @@ -9,29 +9,22 @@ use App\Http\Requests\UpdateTouchpointRequest; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Arr; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class TouchpointController extends Controller implements HasMiddleware +#[Middleware('auth')] +class TouchpointController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-touchpoint')] public function index(): View { - Gate::authorize('show-touchpoint'); - $staff = \App\Models\Touchpoint::groupBy('staff_id')->select('staff_id')->with('staff')->get()->sortBy('staff.sort_name')->pluck('staff.sort_name', 'staff_id'); $touchpoints = \App\Models\Touchpoint::orderBy('touched_at', 'desc')->with('person.prefix', 'person.suffix', 'staff.prefix', 'staff.suffix')->paginate(25, ['*'], 'touchpoints'); @@ -41,10 +34,9 @@ public function index(): View /** * Display a listing of touchpoints associated with a particular staff member */ + #[Authorize('show-touchpoint')] public function index_type(?int $staff_id = null): View { - Gate::authorize('show-touchpoint'); - $staff = \App\Models\Touchpoint::groupBy('staff_id')->select('staff_id')->with('staff')->get()->sortBy('staff.sort_name')->pluck('staff.sort_name', 'staff_id'); $touchpoints = \App\Models\Touchpoint::whereStaffId($staff_id)->orderBy('touched_at', 'desc')->with('person.prefix', 'person.suffix', 'staff.prefix', 'staff.suffix')->paginate(25, ['*'], 'touchpoints'); @@ -54,9 +46,9 @@ public function index_type(?int $staff_id = null): View /** * Show the form for creating a new resource. */ + #[Authorize('create-touchpoint')] public function create(Request $request): View { - Gate::authorize('create-touchpoint'); $staff = \App\Models\Contact::with('groups')->whereHas('groups', function ($query) { $query->where('group_id', '=', config('polanco.group_id.staff')); })->orderBy('sort_name')->pluck('sort_name', 'id'); @@ -76,9 +68,9 @@ public function create(Request $request): View return view('touchpoints.create', compact('staff', 'persons', 'defaults')); } + #[Authorize('create-touchpoint')] public function add_group(Request $request, $group_id = 0): View { - Gate::authorize('create-touchpoint'); $staff = \App\Models\Contact::with('groups')->whereHas('groups', function ($query) { $query->where('group_id', '=', config('polanco.group_id.staff')); })->orderBy('sort_name')->pluck('sort_name', 'id'); @@ -101,9 +93,9 @@ public function add_group(Request $request, $group_id = 0): View return view('touchpoints.add_group', compact('staff', 'groups', 'defaults')); } + #[Authorize('create-touchpoint')] public function add_retreat(Request $request, $event_id = 0): View { - Gate::authorize('create-touchpoint'); $staff = \App\Models\Contact::with('groups')->whereHas('groups', function ($query) { $query->where('group_id', '=', config('polanco.group_id.staff')); })->orderBy('sort_name')->pluck('sort_name', 'id'); @@ -129,9 +121,9 @@ public function add_retreat(Request $request, $event_id = 0): View return view('touchpoints.add_retreat', compact('staff', 'retreat', 'retreats', 'participants', 'defaults')); } + #[Authorize('create-touchpoint')] public function add_retreat_waitlist(Request $request, $event_id = 0): View { - Gate::authorize('create-touchpoint'); $staff = \App\Models\Contact::with('groups')->whereHas('groups', function ($query) { $query->where('group_id', '=', config('polanco.group_id.staff')); })->orderBy('sort_name')->pluck('sort_name', 'id'); @@ -157,10 +149,9 @@ public function add_retreat_waitlist(Request $request, $event_id = 0): View return view('touchpoints.add_retreat_waitlist', compact('staff', 'retreat', 'retreats', 'participants', 'defaults')); } + #[Authorize('create-touchpoint')] public function add(Request $request, $id): View { - Gate::authorize('create-touchpoint'); - // lookup the contact type of the touchpoint being added and show similar ones in drop down (persons, parishes, etc.) $contact = \App\Models\Contact::findOrFail($id); if (isset($contact->subcontact_type)) { @@ -192,10 +183,9 @@ public function add(Request $request, $id): View /** * Store a newly created resource in storage. */ + #[Authorize('create-touchpoint')] public function store(StoreTouchpointRequest $request): RedirectResponse { - Gate::authorize('create-touchpoint'); - $touchpoint = new \App\Models\Touchpoint; $touchpoint->person_id = $request->input('person_id'); $touchpoint->staff_id = $request->input('staff_id'); @@ -209,9 +199,9 @@ public function store(StoreTouchpointRequest $request): RedirectResponse return Redirect::action([self::class, 'index']); } + #[Authorize('create-touchpoint')] public function store_group(StoreGroupTouchpointRequest $request): RedirectResponse { - Gate::authorize('create-touchpoint'); $group_id = $request->input('group_id'); $group = \App\Models\Group::findOrFail($group_id); $group_members = \App\Models\GroupContact::whereGroupId($group_id)->whereStatus('Added')->get(); @@ -230,9 +220,9 @@ public function store_group(StoreGroupTouchpointRequest $request): RedirectRespo return Redirect::action([\App\Http\Controllers\GroupController::class, 'show'], $group_id); } + #[Authorize('create-touchpoint')] public function store_retreat(StoreRetreatTouchpointRequest $request): RedirectResponse { - Gate::authorize('create-touchpoint'); $event_id = $request->input('event_id'); $event = \App\Models\Retreat::findOrFail($event_id); $participants = \App\Models\Registration::whereStatusId(config('polanco.registration_status_id.registered'))->whereEventId($event_id)->whereRoleId(config('polanco.participant_role_id.retreatant'))->whereNull('canceled_at')->get(); @@ -251,9 +241,9 @@ public function store_retreat(StoreRetreatTouchpointRequest $request): RedirectR return Redirect::action([\App\Http\Controllers\RetreatController::class, 'show'], $event_id); } + #[Authorize('create-touchpoint')] public function store_retreat_waitlist(StoreRetreatWaitlistTouchpointRequest $request): RedirectResponse { - Gate::authorize('create-touchpoint'); $event_id = $request->input('event_id'); $event = \App\Models\Retreat::findOrFail($event_id); $participants = \App\Models\Registration::whereStatusId(config('polanco.registration_status_id.waitlist'))->whereEventId($event_id)->whereRoleId(config('polanco.participant_role_id.retreatant'))->whereNull('canceled_at')->get(); @@ -275,9 +265,9 @@ public function store_retreat_waitlist(StoreRetreatWaitlistTouchpointRequest $re /** * Display the specified resource. */ + #[Authorize('show-touchpoint')] public function show(int $id): View { - Gate::authorize('show-touchpoint'); $touchpoint = \App\Models\Touchpoint::with('staff', 'person')->findOrFail($id); return view('touchpoints.show', compact('touchpoint')); // @@ -286,9 +276,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-touchpoint')] public function edit(int $id): View { - Gate::authorize('update-touchpoint'); $touchpoint = \App\Models\Touchpoint::with('staff', 'person')->findOrFail($id); $staff = \App\Models\Contact::with('groups')->whereHas('groups', function ($query) { @@ -319,9 +309,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-touchpoint')] public function update(UpdateTouchpointRequest $request, int $id): RedirectResponse { - Gate::authorize('update-touchpoint'); $touchpoint = \App\Models\Touchpoint::findOrFail($request->input('id')); $touchpoint->person_id = $request->input('person_id'); $touchpoint->staff_id = $request->input('staff_id'); @@ -338,10 +328,9 @@ public function update(UpdateTouchpointRequest $request, int $id): RedirectRespo /** * Remove the specified resource from storage. */ + #[Authorize('delete-touchpoint')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-touchpoint'); - \App\Models\Touchpoint::destroy($id); flash('Touchpoint ID#: '.$id.' deleted')->warning()->important(); diff --git a/app/Http/Controllers/UomController.php b/app/Http/Controllers/UomController.php index fb72994ee..38d5ed49c 100644 --- a/app/Http/Controllers/UomController.php +++ b/app/Http/Controllers/UomController.php @@ -5,23 +5,17 @@ use App\Http\Requests\StoreUomRequest; use App\Http\Requests\UpdateUomRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class UomController extends Controller implements HasMiddleware +#[Middleware('auth')] +class UomController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-uom')] public function index(): View { - Gate::authorize('show-uom'); $uoms = \App\Models\Uom::orderBy('unit_name')->get(); return view('admin.uoms.index', compact('uoms')); @@ -30,9 +24,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-uom')] public function create(): View { - Gate::authorize('create-uom'); $uom_types = config('polanco.uom_types'); return view('admin.uoms.create', compact('uom_types')); @@ -41,10 +35,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-uom')] public function store(StoreUomRequest $request): RedirectResponse { - Gate::authorize('create-uom'); - $uom = new \App\Models\Uom; $uom->type = $request->input('type'); $uom->unit_name = $request->input('unit_name'); @@ -62,10 +55,9 @@ public function store(StoreUomRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-uom')] public function show(int $id): View { - Gate::authorize('show-uom'); - $uom = \App\Models\Uom::findOrFail($id); return view('admin.uoms.show', compact('uom')); @@ -74,10 +66,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-uom')] public function edit(int $id): View { - Gate::authorize('update-uom'); - $uom = \App\Models\Uom::findOrFail($id); $uom_types = config('polanco.uom_types'); @@ -87,10 +78,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-uom')] public function update(UpdateUomRequest $request, int $id): RedirectResponse { - Gate::authorize('update-uom'); - $uom = \App\Models\Uom::findOrFail($id); $uom->type = $request->input('type'); @@ -109,9 +99,9 @@ public function update(UpdateUomRequest $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-uom')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-uom'); $uom = \App\Models\Uom::findOrFail($id); \App\Models\Uom::destroy($id); diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 4889bb9f3..adfd86ccc 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -4,23 +4,17 @@ use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class UserController extends Controller implements HasMiddleware +#[Middleware('auth')] +class UserController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-role')] public function index(): View { - Gate::authorize('show-role'); $users = \App\Models\User::orderBy('name')->with('roles.permissions')->paginate(25, ['*'], 'users'); return view('admin.users.index', compact('users')); @@ -29,9 +23,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-role')] public function create(): RedirectResponse { - Gate::authorize('create-role'); flash('Users cannot be created directly by the controller. Users are only created after successful authentication')->error(); return Redirect::action([self::class, 'index']); @@ -40,9 +34,9 @@ public function create(): RedirectResponse /** * Store a newly created resource in storage. */ + #[Authorize('create-role')] public function store(Request $request): RedirectResponse { - Gate::authorize('create-role'); flash('Users cannot be stored directly by the controller. Users are only created after successful authentication.')->error(); return Redirect::action([self::class, 'index']); @@ -51,10 +45,9 @@ public function store(Request $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-role')] public function show(int $id): View { - Gate::authorize('show-role'); - $user = \App\Models\User::with('roles')->findOrFail($id); return view('admin.users.show', compact('user')); // @@ -63,9 +56,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-role')] public function edit(int $id): RedirectResponse { - Gate::authorize('update-role'); flash('Users cannot be edited directly by the controller. Users are managed by Google authentication.')->error(); return Redirect::action([self::class, 'show'], $id); @@ -74,9 +67,9 @@ public function edit(int $id): RedirectResponse /** * Update the specified resource in storage. */ + #[Authorize('update-role')] public function update(Request $request, int $id): RedirectResponse { - Gate::authorize('update-role'); flash('Users cannot be updated directly by the controller. User profiles are managed by Google authentication.')->error(); return Redirect::action([self::class, 'show'], $id); @@ -85,9 +78,9 @@ public function update(Request $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-role')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-role'); flash('Users cannot be deleted directly by the controller. Users are managed by Google authentication.')->error(); return Redirect::action([self::class, 'show'], $id); diff --git a/app/Http/Controllers/VendorController.php b/app/Http/Controllers/VendorController.php index 26991b0a6..b11832c57 100644 --- a/app/Http/Controllers/VendorController.php +++ b/app/Http/Controllers/VendorController.php @@ -5,26 +5,20 @@ use App\Http\Requests\StoreVendorRequest; use App\Http\Requests\UpdateVendorRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class VendorController extends Controller implements HasMiddleware +#[Middleware('auth')] +class VendorController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - /** * Display a listing of the resource. */ + #[Authorize('show-contact')] public function index(): View { - Gate::authorize('show-contact'); $vendors = \App\Models\Contact::whereSubcontactType(config('polanco.contact_type.vendor'))->orderBy('sort_name', 'asc')->with('addresses.state', 'phones', 'emails', 'websites')->paginate(25, ['*'], 'vendors'); return view('vendors.index', compact('vendors')); // @@ -33,10 +27,9 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-contact')] public function create(): View { - Gate::authorize('create-contact'); - $states = \App\Models\StateProvince::orderby('name')->whereCountryId(config('polanco.country_id_usa'))->pluck('name', 'id'); $states->prepend('N/A', 0); $countries = \App\Models\Country::orderby('iso_code')->pluck('iso_code', 'id'); @@ -50,10 +43,9 @@ public function create(): View /** * Store a newly created resource in storage. */ + #[Authorize('create-contact')] public function store(StoreVendorRequest $request): RedirectResponse { - Gate::authorize('create-contact'); - $vendor = new \App\Models\Contact; $vendor->organization_name = $request->input('organization_name'); $vendor->display_name = $request->input('organization_name'); @@ -156,9 +148,9 @@ public function store(StoreVendorRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-contact')] public function show(int $id): View { - Gate::authorize('show-contact'); $vendor = \App\Models\Contact::with('addresses.state', 'addresses.location', 'phones.location', 'emails.location', 'websites', 'notes')->findOrFail($id); $donations = \App\Models\Donation::whereContactId($id)->with('payments')->orderBy('donation_date', 'DESC')->paginate(25, ['*'], 'donations'); $touchpoints = \App\Models\Touchpoint::wherePersonId($id)->orderBy('touched_at', 'DESC')->paginate(25, ['*'], 'touchpoints'); @@ -177,10 +169,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-contact')] public function edit(int $id): View { - Gate::authorize('update-contact'); - $states = \App\Models\StateProvince::orderby('name')->whereCountryId(config('polanco.country_id_usa'))->pluck('name', 'id'); $states->prepend('N/A', 0); $countries = \App\Models\Country::orderby('iso_code')->pluck('iso_code', 'id'); @@ -208,10 +199,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-contact')] public function update(UpdateVendorRequest $request, int $id): RedirectResponse { - Gate::authorize('update-contact'); - $vendor = \App\Models\Contact::with('address_primary.state', 'address_primary.location', 'phone_primary.location', 'phone_main_fax', 'email_primary.location', 'website_main', 'notes')->findOrFail($request->input('id')); $vendor->organization_name = $request->input('organization_name'); $vendor->display_name = $request->input('display_name'); @@ -340,10 +330,9 @@ public function update(UpdateVendorRequest $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-contact')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-contact'); - $vendor = \App\Models\Vendor::findOrFail($id); \App\Models\Relationship::whereContactIdA($id)->delete(); \App\Models\Relationship::whereContactIdB($id)->delete(); diff --git a/app/Http/Controllers/WebsiteController.php b/app/Http/Controllers/WebsiteController.php index 2f850ccd6..ad039404f 100644 --- a/app/Http/Controllers/WebsiteController.php +++ b/app/Http/Controllers/WebsiteController.php @@ -5,23 +5,17 @@ use App\Http\Requests\StoreWebsiteRequest; use App\Http\Requests\UpdateWebsiteRequest; use Illuminate\Http\RedirectResponse; -use Illuminate\Routing\Controllers\HasMiddleware; -use Illuminate\Support\Facades\Gate; +use Illuminate\Routing\Attributes\Controllers\Authorize; +use Illuminate\Routing\Attributes\Controllers\Middleware; use Illuminate\Support\Facades\Redirect; use Illuminate\View\View; -class WebsiteController extends Controller implements HasMiddleware +#[Middleware('auth')] +class WebsiteController extends Controller { - public static function middleware(): array - { - return [ - 'auth', - ]; - } - + #[Authorize('show-website')] public function index(): View { - Gate::authorize('show-website'); $websites = \App\Models\Website::orderBy('url')->whereNotNull('url')->paginate(25, ['*'], 'websites'); return view('admin.websites.index', compact('websites')); @@ -30,20 +24,18 @@ public function index(): View /** * Show the form for creating a new resource. */ + #[Authorize('create-website')] public function create(): View { - Gate::authorize('create-website'); - return view('admin.websites.create'); } /** * Store a newly created resource in storage. */ + #[Authorize('create-website')] public function store(StoreWebsiteRequest $request): RedirectResponse { - Gate::authorize('create-website'); - $website = new \App\Models\Website; $website->contact_id = $request->input('contact_id'); $website->url = $request->input('url'); @@ -61,10 +53,9 @@ public function store(StoreWebsiteRequest $request): RedirectResponse /** * Display the specified resource. */ + #[Authorize('show-website')] public function show(int $id): View { - Gate::authorize('show-website'); - $website = \App\Models\Website::findOrFail($id); return view('admin.websites.show', compact('website')); @@ -73,10 +64,9 @@ public function show(int $id): View /** * Show the form for editing the specified resource. */ + #[Authorize('update-website')] public function edit(int $id): View { - Gate::authorize('update-website'); - $website = \App\Models\Website::findOrFail($id); return view('admin.websites.edit', compact('website')); // @@ -85,10 +75,9 @@ public function edit(int $id): View /** * Update the specified resource in storage. */ + #[Authorize('update-website')] public function update(UpdateWebsiteRequest $request, int $id): RedirectResponse { - Gate::authorize('update-website'); - $website = \App\Models\Website::findOrFail($id); $website->contact_id = $request->input('contact_id'); @@ -107,9 +96,9 @@ public function update(UpdateWebsiteRequest $request, int $id): RedirectResponse /** * Remove the specified resource from storage. */ + #[Authorize('delete-website')] public function destroy(int $id): RedirectResponse { - Gate::authorize('delete-website'); $website = \App\Models\Website::findOrFail($id); \App\Models\Website::destroy($id); diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 19db3aac2..ab1c4ca97 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -9,14 +10,13 @@ use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('activity')] class Activity extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'activity'; - protected function casts(): array { return [ diff --git a/app/Models/ActivityContact.php b/app/Models/ActivityContact.php index a7eb2b8f7..5bb31dcab 100644 --- a/app/Models/ActivityContact.php +++ b/app/Models/ActivityContact.php @@ -2,20 +2,20 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('activity_contact')] class ActivityContact extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'activity_contact'; - public function activity(): HasOne { return $this->hasOne(Activity::class, 'id', 'activity_id'); diff --git a/app/Models/ActivityStatus.php b/app/Models/ActivityStatus.php index 0683b0d24..2963655b9 100644 --- a/app/Models/ActivityStatus.php +++ b/app/Models/ActivityStatus.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('activity_status')] class ActivityStatus extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'activity_status'; } diff --git a/app/Models/ActivityType.php b/app/Models/ActivityType.php index 513d11dc6..dbbdab4c2 100644 --- a/app/Models/ActivityType.php +++ b/app/Models/ActivityType.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('activity_type')] class ActivityType extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'activity_type'; } diff --git a/app/Models/Address.php b/app/Models/Address.php index 55568933e..932be9cff 100644 --- a/app/Models/Address.php +++ b/app/Models/Address.php @@ -2,6 +2,8 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -9,16 +11,14 @@ use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('address')] +#[Fillable('contact_id', 'location_type_id', 'is_primary', 'street_address', 'supplemental_address_1', 'city', 'state_province_id', 'postal_code', 'country_id')] class Address extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'address'; - - protected $fillable = ['contact_id', 'location_type_id', 'is_primary', 'street_address', 'supplemental_address_1', 'city', 'state_province_id', 'postal_code', 'country_id']; - // the contact for whom this is an address for public function addressee(): BelongsTo { diff --git a/app/Models/Agc2019.php b/app/Models/Agc2019.php index 6eef9917a..28ff837e6 100644 --- a/app/Models/Agc2019.php +++ b/app/Models/Agc2019.php @@ -2,23 +2,21 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; +use Illuminate\Database\Eloquent\Attributes\WithoutTimestamps; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use OwenIt\Auditing\Contracts\Auditable; +#[Table('agc_household_name', 'contact_id')] +#[WithoutTimestamps] +#[Fillable('contact_id')] class Agc2019 extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; - protected $table = 'agc_household_name'; - - protected $fillable = ['contact_id']; - - protected $primaryKey = 'contact_id'; - - public $timestamps = false; - protected function casts(): array { return [ diff --git a/app/Models/Asset.php b/app/Models/Asset.php index aa7498894..ed2f9e510 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Attributes\Scope; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -12,14 +13,13 @@ use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('asset')] class Asset extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'asset'; - protected function casts(): array { return [ diff --git a/app/Models/AssetJob.php b/app/Models/AssetJob.php index 35d87deb5..534b3d361 100644 --- a/app/Models/AssetJob.php +++ b/app/Models/AssetJob.php @@ -2,20 +2,20 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('asset_job')] class AssetJob extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'asset_job'; - protected function casts(): array { return [ diff --git a/app/Models/AssetTask.php b/app/Models/AssetTask.php index b1cef0784..73355e528 100644 --- a/app/Models/AssetTask.php +++ b/app/Models/AssetTask.php @@ -2,20 +2,20 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('asset_task')] class AssetTask extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'asset_task'; - protected function casts(): array { return [ diff --git a/app/Models/AssetType.php b/app/Models/AssetType.php index e3f83b9a4..dfee25c13 100644 --- a/app/Models/AssetType.php +++ b/app/Models/AssetType.php @@ -3,20 +3,20 @@ namespace App\Models; use Illuminate\Database\Eloquent\Attributes\Scope; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('asset_type')] class AssetType extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'asset_type'; - #[Scope] protected function active($query) { diff --git a/app/Models/Attachment.php b/app/Models/Attachment.php index dc0af33fc..db7dea18e 100644 --- a/app/Models/Attachment.php +++ b/app/Models/Attachment.php @@ -2,23 +2,22 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('file')] +#[Fillable('entity', 'entity_id', 'file_type_id')] class Attachment extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'file'; - - // - protected $fillable = ['entity', 'entity_id', 'file_type_id']; - protected function casts(): array { return [ diff --git a/app/Models/Audit.php b/app/Models/Audit.php index f7db0efdc..586520777 100644 --- a/app/Models/Audit.php +++ b/app/Models/Audit.php @@ -2,20 +2,20 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Appends; use Illuminate\Database\Eloquent\Attributes\Scope; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Support\Carbon; +#[Table('audits')] +#[Appends('user_name')] class Audit extends Model { use HasFactory; - protected $table = 'audits'; - - protected $appends = ['user_name']; - protected function casts(): array { return [ diff --git a/app/Models/Contact.php b/app/Models/Contact.php index d2c8e6037..d17e8ef79 100644 --- a/app/Models/Contact.php +++ b/app/Models/Contact.php @@ -3,7 +3,9 @@ namespace App\Models; use Carbon\Carbon; +use Illuminate\Database\Eloquent\Attributes\Appends; use Illuminate\Database\Eloquent\Attributes\Scope; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; @@ -14,6 +16,8 @@ use Laravel\Cashier\Billable; use OwenIt\Auditing\Contracts\Auditable; +#[Table('contact')] +#[Appends('full_name_with_city', 'agc_household_name')] class Contact extends Model implements Auditable { use Billable; @@ -21,10 +25,6 @@ class Contact extends Model implements Auditable use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'contact'; - - protected $appends = ['full_name_with_city', 'agc_household_name']; - protected $with = ['prefix', 'suffix']; protected function casts(): array diff --git a/app/Models/ContactLanguage.php b/app/Models/ContactLanguage.php index 07bdc6a0b..15c37da56 100644 --- a/app/Models/ContactLanguage.php +++ b/app/Models/ContactLanguage.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('contact_languages')] +#[Fillable('contact_id', 'language_id')] class ContactLanguage extends Model implements Auditable { use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'contact_languages'; - - protected $fillable = ['contact_id', 'language_id']; } diff --git a/app/Models/ContactReferral.php b/app/Models/ContactReferral.php index 3d48e6bda..b3af278c2 100644 --- a/app/Models/ContactReferral.php +++ b/app/Models/ContactReferral.php @@ -2,14 +2,14 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('contact_referral')] class ContactReferral extends Model implements Auditable { use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'contact_referral'; } diff --git a/app/Models/ContactType.php b/app/Models/ContactType.php index fe5de75cc..9fe5448ce 100644 --- a/app/Models/ContactType.php +++ b/app/Models/ContactType.php @@ -3,19 +3,19 @@ namespace App\Models; use Illuminate\Database\Eloquent\Attributes\Scope; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('contact_type')] class ContactType extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'contact_type'; - // generic organizations that are not dioceses, parishes, etc. #[Scope] protected function generic($query) diff --git a/app/Models/Country.php b/app/Models/Country.php index 3c6e695da..c05d1d4bf 100644 --- a/app/Models/Country.php +++ b/app/Models/Country.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('country')] class Country extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'country'; } diff --git a/app/Models/Department.php b/app/Models/Department.php index f76691dcd..c808a3149 100644 --- a/app/Models/Department.php +++ b/app/Models/Department.php @@ -3,20 +3,20 @@ namespace App\Models; use Illuminate\Database\Eloquent\Attributes\Scope; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('departments')] class Department extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'departments'; - #[Scope] protected function active($query) { diff --git a/app/Models/Diocese.php b/app/Models/Diocese.php index d2a378e95..d6f192a5e 100644 --- a/app/Models/Diocese.php +++ b/app/Models/Diocese.php @@ -2,18 +2,18 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; +#[Table('contact')] class Diocese extends Model { use HasFactory; use SoftDeletes; - protected $table = 'contact'; - public function getNoteDioceseTextAttribute() { if (isset($this->note_diocese->note)) { diff --git a/app/Models/Donation.php b/app/Models/Donation.php index 26451ee87..3abf87704 100644 --- a/app/Models/Donation.php +++ b/app/Models/Donation.php @@ -3,7 +3,10 @@ namespace App\Models; use Carbon\Carbon; +use Illuminate\Database\Eloquent\Attributes\Appends; +use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Attributes\Scope; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -12,20 +15,15 @@ use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('Donations', 'donation_id')] +#[Fillable('donation_id', 'donor_id', 'donation_description', 'donation_amount', 'payment_description', 'Notes', 'contact_id')] +#[Appends('payments_paid')] class Donation extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'Donations'; - - protected $fillable = ['donation_id', 'donor_id', 'donation_description', 'donation_amount', 'payment_description', 'Notes', 'contact_id']; - - protected $primaryKey = 'donation_id'; - - protected $appends = ['payments_paid']; - protected function casts(): array { return [ diff --git a/app/Models/DonationType.php b/app/Models/DonationType.php index 43a519233..2f87d408f 100644 --- a/app/Models/DonationType.php +++ b/app/Models/DonationType.php @@ -3,11 +3,13 @@ namespace App\Models; use Illuminate\Database\Eloquent\Attributes\Scope; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('donation_type')] class DonationType extends Model implements Auditable { /* @@ -23,8 +25,6 @@ class DonationType extends Model implements Auditable use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'donation_type'; - #[Scope] protected function active($query) { diff --git a/app/Models/Donor.php b/app/Models/Donor.php index 9bc0f711c..a9783fa8a 100644 --- a/app/Models/Donor.php +++ b/app/Models/Donor.php @@ -2,6 +2,8 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; +use Illuminate\Database\Eloquent\Attributes\WithoutTimestamps; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -10,17 +12,13 @@ // imported table from PPD - not actively used in Polanco - stored for archival purposes // use Illuminate\Database\Eloquent\SoftDeletes; +#[Table('Donors')] +#[WithoutTimestamps] class Donor extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; - // use SoftDeletes; - protected $table = 'Donors'; - - // protected $primaryKey = 'donor_id'; - public $timestamps = false; - public function donations(): HasMany { return $this->hasMany(Donation::class, 'donor_id', 'donor_id'); diff --git a/app/Models/Email.php b/app/Models/Email.php index 560218d3d..9f01d567f 100644 --- a/app/Models/Email.php +++ b/app/Models/Email.php @@ -2,22 +2,22 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('email')] +#[Fillable('contact_id', 'location_type_id', 'is_primary', 'email')] class Email extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'email'; - - protected $fillable = ['contact_id', 'location_type_id', 'is_primary', 'email']; - public function owner(): BelongsTo { return $this->belongsTo(Contact::class, 'contact_id', 'id'); diff --git a/app/Models/EmergencyContact.php b/app/Models/EmergencyContact.php index 9a68c144b..51bb76b07 100644 --- a/app/Models/EmergencyContact.php +++ b/app/Models/EmergencyContact.php @@ -2,22 +2,22 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('emergency_contact')] +#[Fillable('contact_id', 'name', 'relationship', 'phone', 'phone_alternate')] class EmergencyContact extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'emergency_contact'; - - protected $fillable = ['contact_id', 'name', 'relationship', 'phone', 'phone_alternate']; - public function contact(): BelongsTo { return $this->belongsTo(Contact::class, 'contact_id', 'id'); diff --git a/app/Models/EventType.php b/app/Models/EventType.php index 40b01a0bf..332b9cacc 100644 --- a/app/Models/EventType.php +++ b/app/Models/EventType.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('event_type')] class EventType extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'event_type'; } diff --git a/app/Models/ExportList.php b/app/Models/ExportList.php index 18fb48849..fe27b1b5a 100644 --- a/app/Models/ExportList.php +++ b/app/Models/ExportList.php @@ -2,19 +2,19 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('export_list')] class ExportList extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'export_list'; - protected function casts(): array { return [ diff --git a/app/Models/ExportListAgc.php b/app/Models/ExportListAgc.php index ecc3c53fa..886095a77 100644 --- a/app/Models/ExportListAgc.php +++ b/app/Models/ExportListAgc.php @@ -2,14 +2,14 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('export_list_agc')] class ExportListAgc extends Model implements Auditable { use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'export_list_agc'; } diff --git a/app/Models/Gender.php b/app/Models/Gender.php index 2244ecead..797424a7e 100644 --- a/app/Models/Gender.php +++ b/app/Models/Gender.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('gender')] class Gender extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'gender'; } diff --git a/app/Models/GiftCertificate.php b/app/Models/GiftCertificate.php index 9b72a9657..6b434a603 100644 --- a/app/Models/GiftCertificate.php +++ b/app/Models/GiftCertificate.php @@ -2,7 +2,9 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Appends; use Illuminate\Database\Eloquent\Attributes\Scope; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -10,16 +12,14 @@ use OwenIt\Auditing\Contracts\Auditable; use PDF; +#[Table('gift_certificate')] +#[Appends('certificate_number')] class GiftCertificate extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'gift_certificate'; - - protected $appends = ['certificate_number']; - protected function casts(): array { return [ diff --git a/app/Models/Group.php b/app/Models/Group.php index a2236be28..cc61d302b 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -2,20 +2,20 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('group')] class Group extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'group'; - public function members(): HasMany { return $this->hasMany(GroupContact::class, 'group_id', 'id'); diff --git a/app/Models/GroupContact.php b/app/Models/GroupContact.php index 694c531cc..fac22f116 100644 --- a/app/Models/GroupContact.php +++ b/app/Models/GroupContact.php @@ -2,22 +2,22 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('group_contact')] +#[Fillable('contact_id', 'group_id', 'status')] class GroupContact extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'group_contact'; - - protected $fillable = ['contact_id', 'group_id', 'status']; - public function group(): BelongsTo { return $this->belongsTo(Group::class, 'group_id', 'id'); diff --git a/app/Models/Language.php b/app/Models/Language.php index ce5851629..bf3fb4ad4 100644 --- a/app/Models/Language.php +++ b/app/Models/Language.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('language')] class Language extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'language'; } diff --git a/app/Models/LocationType.php b/app/Models/LocationType.php index 7d60942f2..d3e5150f7 100644 --- a/app/Models/LocationType.php +++ b/app/Models/LocationType.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('location_type')] class LocationType extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'location_type'; } diff --git a/app/Models/Message.php b/app/Models/Message.php index d083b5032..6581dd8fb 100644 --- a/app/Models/Message.php +++ b/app/Models/Message.php @@ -2,20 +2,20 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Fillable('mailgun_id', 'mailgun_timestamp', 'storage_url', 'from', 'to', 'subject', 'from_id', 'to_id', 'is_processed')] class Message extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $fillable = ['mailgun_id', 'mailgun_timestamp', 'storage_url', 'from', 'to', 'subject', 'from_id', 'to_id', 'is_processed']; - protected function casts(): array { return [ diff --git a/app/Models/MessageAttachment.php b/app/Models/MessageAttachment.php index efee660c4..733caea79 100644 --- a/app/Models/MessageAttachment.php +++ b/app/Models/MessageAttachment.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Fillable('mailgun_id', 'mailgun_timestamp', 'attachment_id', 'url', 'content_type')] class MessageAttachment extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $fillable = ['mailgun_id', 'mailgun_timestamp', 'attachment_id', 'url', 'content_type']; } diff --git a/app/Models/Note.php b/app/Models/Note.php index 493ee7ba7..986d9b624 100644 --- a/app/Models/Note.php +++ b/app/Models/Note.php @@ -2,18 +2,18 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('note')] +#[Fillable('entity_table', 'entity_id', 'note', 'contact_id', 'subject', 'privacy')] class Note extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'note'; - - protected $fillable = ['entity_table', 'entity_id', 'note', 'contact_id', 'subject', 'privacy']; } diff --git a/app/Models/Organization.php b/app/Models/Organization.php index 7cbca84dd..e17808494 100644 --- a/app/Models/Organization.php +++ b/app/Models/Organization.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +#[Table('contact')] class Organization extends Model { use HasFactory; use SoftDeletes; - protected $table = 'contact'; - // } diff --git a/app/Models/Parish.php b/app/Models/Parish.php index 186f404ab..63457b8e4 100644 --- a/app/Models/Parish.php +++ b/app/Models/Parish.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -9,13 +10,12 @@ use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; +#[Table('contact')] class Parish extends Model { use HasFactory; use SoftDeletes; - protected $table = 'contact'; - // public function diocese(): BelongsTo { diff --git a/app/Models/ParticipantRoleType.php b/app/Models/ParticipantRoleType.php index d06c5c66d..dce4ce6ec 100644 --- a/app/Models/ParticipantRoleType.php +++ b/app/Models/ParticipantRoleType.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('participant_role_type')] class ParticipantRoleType extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'participant_role_type'; } diff --git a/app/Models/ParticipantStatus.php b/app/Models/ParticipantStatus.php index 8cfcebbaa..0e756bdb9 100644 --- a/app/Models/ParticipantStatus.php +++ b/app/Models/ParticipantStatus.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('participant_status_type')] class ParticipantStatus extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'participant_status_type'; } diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 2cc47ebcb..ed15a9bd1 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -3,25 +3,23 @@ namespace App\Models; use Carbon\Carbon; +use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Attributes\Scope; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('Donations_payment', 'payment_id')] +#[Fillable('donation_id', 'payment_id', 'payment_amount', 'payment_description', 'cknumber', 'ccnumber', 'authorization_number', 'note', 'ty_letter_sent')] class Payment extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'Donations_payment'; - - protected $fillable = ['donation_id', 'payment_id', 'payment_amount', 'payment_description', 'cknumber', 'ccnumber', 'authorization_number', 'note', 'ty_letter_sent']; - - protected $primaryKey = 'payment_id'; - protected function casts(): array { return [ diff --git a/app/Models/Phone.php b/app/Models/Phone.php index 0a9ea2b46..613b6b372 100644 --- a/app/Models/Phone.php +++ b/app/Models/Phone.php @@ -3,12 +3,16 @@ namespace App\Models; use App\Traits\PhoneTrait; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('phone')] +#[Fillable('contact_id', 'location_type_id', 'is_primary', 'phone', 'phone_type')] class Phone extends Model implements Auditable { use HasFactory; @@ -16,10 +20,6 @@ class Phone extends Model implements Auditable use PhoneTrait; use SoftDeletes; - protected $table = 'phone'; - - protected $fillable = ['contact_id', 'location_type_id', 'is_primary', 'phone', 'phone_type']; - public function owner(): BelongsTo { return $this->belongsTo(Contact::class, 'contact_id', 'id'); diff --git a/app/Models/Prefix.php b/app/Models/Prefix.php index a1496b51b..9d90b50df 100644 --- a/app/Models/Prefix.php +++ b/app/Models/Prefix.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('prefix')] class Prefix extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'prefix'; } diff --git a/app/Models/Referral.php b/app/Models/Referral.php index a0da51663..e21d45b90 100644 --- a/app/Models/Referral.php +++ b/app/Models/Referral.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('referral')] class Referral extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'referral'; } diff --git a/app/Models/Registration.php b/app/Models/Registration.php index 002d23ba6..c75e1f212 100644 --- a/app/Models/Registration.php +++ b/app/Models/Registration.php @@ -2,6 +2,9 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Appends; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -10,18 +13,15 @@ use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('participant')] +#[Fillable('contact_id', 'event_id', 'status_id', 'role_id', 'notes', 'register_date')] +#[Appends('retreat_start_date')] class Registration extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'participant'; - - protected $fillable = ['contact_id', 'event_id', 'status_id', 'role_id', 'notes', 'register_date']; - - protected $appends = ['retreat_start_date']; - protected function casts(): array { return [ diff --git a/app/Models/Relationship.php b/app/Models/Relationship.php index 159ab70e2..d33b81c0d 100644 --- a/app/Models/Relationship.php +++ b/app/Models/Relationship.php @@ -2,24 +2,24 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Appends; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('relationship')] +#[Fillable('contact_id_a', 'contact_id_b', 'relationship_type_id', 'is_active', 'description')] +#[Appends('contact_a_address', 'contact_b_address')] class Relationship extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'relationship'; - - protected $fillable = ['contact_id_a', 'contact_id_b', 'relationship_type_id', 'is_active', 'description']; - - protected $appends = ['contact_a_address', 'contact_b_address']; - public function relationship_type(): HasOne { return $this->hasOne(RelationshipType::class, 'id', 'relationship_type_id'); diff --git a/app/Models/RelationshipType.php b/app/Models/RelationshipType.php index c3844e0d6..8895f714f 100644 --- a/app/Models/RelationshipType.php +++ b/app/Models/RelationshipType.php @@ -2,20 +2,20 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('relationship_type')] class RelationshipType extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'relationship_type'; - public function getContactTypeAIdAttribute() { if (! empty($this->contacttype_a)) { diff --git a/app/Models/Religion.php b/app/Models/Religion.php index 45d890fa7..42657a3b9 100644 --- a/app/Models/Religion.php +++ b/app/Models/Religion.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('religion')] class Religion extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'religion'; } diff --git a/app/Models/Retreat.php b/app/Models/Retreat.php index 3b4354225..d886e897e 100644 --- a/app/Models/Retreat.php +++ b/app/Models/Retreat.php @@ -4,6 +4,7 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Attributes\Scope; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -12,6 +13,7 @@ use Illuminate\Support\Facades\Storage; use OwenIt\Auditing\Contracts\Auditable; +#[Table('event')] class Retreat extends Model implements Auditable { use HasFactory; @@ -19,8 +21,6 @@ class Retreat extends Model implements Auditable use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'event'; - protected function casts(): array { return [ diff --git a/app/Models/SquarespaceContribution.php b/app/Models/SquarespaceContribution.php index 747d05c54..070b9197c 100644 --- a/app/Models/SquarespaceContribution.php +++ b/app/Models/SquarespaceContribution.php @@ -3,12 +3,16 @@ namespace App\Models; use App\Traits\PhoneTrait; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('squarespace_contribution')] +#[Fillable('message_id')] class SquarespaceContribution extends Model implements Auditable { use HasFactory; @@ -16,10 +20,6 @@ class SquarespaceContribution extends Model implements Auditable use PhoneTrait; use SoftDeletes; - protected $table = 'squarespace_contribution'; - - protected $fillable = ['message_id']; - public function message(): HasOne { return $this->hasOne(Message::class, 'id', 'message_id'); diff --git a/app/Models/SquarespaceCustomForm.php b/app/Models/SquarespaceCustomForm.php index 08d2949c1..3cfe98384 100644 --- a/app/Models/SquarespaceCustomForm.php +++ b/app/Models/SquarespaceCustomForm.php @@ -2,20 +2,20 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('squarespace_custom_form')] class SquarespaceCustomForm extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'squarespace_custom_form'; - public function fields(): HasMany { return $this->hasMany(SquarespaceCustomFormField::class, 'form_id', 'id'); diff --git a/app/Models/SquarespaceCustomFormField.php b/app/Models/SquarespaceCustomFormField.php index 823278e9b..f982d6862 100644 --- a/app/Models/SquarespaceCustomFormField.php +++ b/app/Models/SquarespaceCustomFormField.php @@ -2,20 +2,20 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('squarespace_custom_form_field')] class SquarespaceCustomFormField extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'squarespace_custom_form_field'; - public function form(): BelongsTo { return $this->belongsTo(SquarespaceCustomForm::class, 'form_id', 'id'); diff --git a/app/Models/SquarespaceInventory.php b/app/Models/SquarespaceInventory.php index d20482a44..b04aab2a8 100644 --- a/app/Models/SquarespaceInventory.php +++ b/app/Models/SquarespaceInventory.php @@ -2,20 +2,20 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('squarespace_inventory')] class SquarespaceInventory extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'squarespace_inventory'; - public function custom_form(): HasOne { return $this->hasOne(SquarespaceCustomForm::class, 'id', 'custom_form_id'); diff --git a/app/Models/SquarespaceOrder.php b/app/Models/SquarespaceOrder.php index 5f01c5c8c..9469a32bf 100644 --- a/app/Models/SquarespaceOrder.php +++ b/app/Models/SquarespaceOrder.php @@ -3,12 +3,16 @@ namespace App\Models; use App\Traits\PhoneTrait; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('squarespace_order')] +#[Fillable('order_number')] class SquarespaceOrder extends Model implements Auditable { use HasFactory; @@ -16,10 +20,6 @@ class SquarespaceOrder extends Model implements Auditable use PhoneTrait; use SoftDeletes; - protected $table = 'squarespace_order'; - - protected $fillable = ['order_number']; - public function message(): HasOne { return $this->hasOne(Message::class, 'id', 'message_id'); diff --git a/app/Models/StateProvince.php b/app/Models/StateProvince.php index cc99f737e..86051c58b 100644 --- a/app/Models/StateProvince.php +++ b/app/Models/StateProvince.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('state_province')] class StateProvince extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'state_province'; } diff --git a/app/Models/StripeBalanceTransaction.php b/app/Models/StripeBalanceTransaction.php index 8971503ee..9520f021d 100644 --- a/app/Models/StripeBalanceTransaction.php +++ b/app/Models/StripeBalanceTransaction.php @@ -2,6 +2,8 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -9,16 +11,14 @@ use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('stripe_balance_transaction')] +#[Fillable('balance_transaction_id', 'payout_id', 'customer_id', 'charge_id', 'total_amount', 'fee_amount', 'net_amount', 'payout_date', 'available_date', 'reconcile_date')] class StripeBalanceTransaction extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'stripe_balance_transaction'; - - protected $fillable = ['balance_transaction_id', 'payout_id', 'customer_id', 'charge_id', 'total_amount', 'fee_amount', 'net_amount', 'payout_date', 'available_date', 'reconcile_date']; - protected function casts(): array { return [ diff --git a/app/Models/StripePayout.php b/app/Models/StripePayout.php index da31613b8..8f9273a2d 100644 --- a/app/Models/StripePayout.php +++ b/app/Models/StripePayout.php @@ -2,22 +2,22 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('stripe_payout')] +#[Fillable('payout_id', 'object', 'amount', 'arrival_date', 'date', 'status', 'total_fee_amount', 'reconcile_date')] class StripePayout extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'stripe_payout'; - - protected $fillable = ['payout_id', 'object', 'amount', 'arrival_date', 'date', 'status', 'total_fee_amount', 'reconcile_date']; - protected function casts(): array { return [ diff --git a/app/Models/Suffix.php b/app/Models/Suffix.php index 96b673d9f..a6b6670b1 100644 --- a/app/Models/Suffix.php +++ b/app/Models/Suffix.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('suffix')] class Suffix extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - - protected $table = 'suffix'; } diff --git a/app/Models/TmpOfferingDedup.php b/app/Models/TmpOfferingDedup.php index 21bbb1360..6a887dcc3 100644 --- a/app/Models/TmpOfferingDedup.php +++ b/app/Models/TmpOfferingDedup.php @@ -2,6 +2,8 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -9,15 +11,12 @@ // use Illuminate\Database\Eloquent\SoftDeletes; +#[Table('tmp_offering_dedup')] +#[Fillable('contact_id', 'event_id')] class TmpOfferingDedup extends Model { use HasFactory; - // use SoftDeletes; - protected $table = 'tmp_offering_dedup'; - - protected $fillable = ['contact_id', 'event_id']; - public function contact(): BelongsTo { return $this->belongsTo(Contact::class, 'contact_id', 'id'); diff --git a/app/Models/Touchpoint.php b/app/Models/Touchpoint.php index dbabb486d..cd9a88945 100644 --- a/app/Models/Touchpoint.php +++ b/app/Models/Touchpoint.php @@ -3,12 +3,14 @@ namespace App\Models; use Carbon\Carbon; +use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Fillable('person_id', 'staff_id', 'notes', 'type')] class Touchpoint extends Model implements Auditable { use HasFactory; @@ -17,8 +19,6 @@ class Touchpoint extends Model implements Auditable // use SoftDeletes; - protected $fillable = ['person_id', 'staff_id', 'notes', 'type']; - protected function casts(): array { return [ diff --git a/app/Models/Uom.php b/app/Models/Uom.php index cf21e7d2f..22462ba11 100644 --- a/app/Models/Uom.php +++ b/app/Models/Uom.php @@ -3,19 +3,19 @@ namespace App\Models; use Illuminate\Database\Eloquent\Attributes\Scope; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('uom')] class Uom extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'uom'; - #[Scope] protected function active($query) { diff --git a/app/Models/User.php b/app/Models/User.php index d5e2f6b55..131410a35 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -3,6 +3,8 @@ namespace App\Models; use App\Traits\HasRoles; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Hidden; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasOne; @@ -10,35 +12,12 @@ use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; +#[Fillable('name', 'email', 'password', 'provider', 'provider_id', 'avatar', 'username')] +#[Hidden('password', 'remember_token')] class User extends Authenticatable { use HasApiTokens, HasFactory, HasRoles, Notifiable; - /** - * The attributes that are mass assignable. - * - * @var array - */ - protected $fillable = [ - 'name', - 'email', - 'password', - 'provider', - 'provider_id', - 'avatar', - 'username', - ]; - - /** - * The attributes that should be hidden for serialization. - * - * @var array - */ - protected $hidden = [ - 'password', - 'remember_token', - ]; - /** * Get the attributes that should be cast. * diff --git a/app/Models/Vendor.php b/app/Models/Vendor.php index 974940673..79b619003 100644 --- a/app/Models/Vendor.php +++ b/app/Models/Vendor.php @@ -2,16 +2,16 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; +#[Table('contact')] class Vendor extends Model { use HasFactory; use SoftDeletes; - protected $table = 'contact'; - // } diff --git a/app/Models/Website.php b/app/Models/Website.php index a81319f1c..5bed63ebd 100644 --- a/app/Models/Website.php +++ b/app/Models/Website.php @@ -2,22 +2,22 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Attributes\Fillable; +use Illuminate\Database\Eloquent\Attributes\Table; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Contracts\Auditable; +#[Table('website')] +#[Fillable('contact_id', 'url', 'website_type')] class Website extends Model implements Auditable { use HasFactory; use \OwenIt\Auditing\Auditable; use SoftDeletes; - protected $table = 'website'; - - protected $fillable = ['contact_id', 'url', 'website_type']; - public function owner(): BelongsTo { return $this->belongsTo(Contact::class, 'contact_id', 'id'); diff --git a/bootstrap/app.php b/bootstrap/app.php index 4a88ac71a..cc46e7672 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -18,7 +18,7 @@ $middleware->redirectGuestsTo(fn () => route('login')); $middleware->redirectUsersTo(AppServiceProvider::HOME); - $middleware->validateCsrfTokens(except: [ + $middleware->preventRequestForgery(except: [ 'stripe/webhooks', ]); diff --git a/composer.json b/composer.json index 6f678a9fe..2bd8abbc3 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ ], "license": "MIT", "require": { - "php": "^8.2", + "php": "^8.3", "barryvdh/laravel-snappy": "^1.0", "doctrine/dbal": "^3.5", "guzzlehttp/guzzle": "^7.8", @@ -19,12 +19,12 @@ "jeremykenedy/laravel-logger": "^10.0", "kriswallsmith/buzz": "^1.3", "laracasts/flash": "^3.2", - "laravel/cashier": "^15.6", - "laravel/framework": "^12.19", - "laravel/helpers": "^1.7", - "laravel/sanctum": "^4.0", - "laravel/socialite": "^5.17", - "laravel/tinker": "^2.10.1", + "laravel/cashier": "^16.5", + "laravel/framework": "^13.7", + "laravel/helpers": "^1.8", + "laravel/sanctum": "^4.3", + "laravel/socialite": "^5.24", + "laravel/tinker": "^3.0", "laravel/ui": "^4.6", "mailgun/mailgun-php": "^3.5", "nyholm/psr7": "^1.5", @@ -33,24 +33,24 @@ "spatie/laravel-google-calendar": "^3.8", "spatie/laravel-stripe-webhooks": "^3.10", "stuyam/laravel-phone-validator": "dev-master", - "symfony/http-client": "^7.2", - "symfony/mailgun-mailer": "^7.2", - "spatie/laravel-html": "^3.11" + "symfony/http-client": "^7.4", + "symfony/mailgun-mailer": "^7.4", + "spatie/laravel-html": "^3.13" }, "require-dev": { - "barryvdh/laravel-debugbar": "^3.15", - "barryvdh/laravel-ide-helper": "^3.5", - "brianium/paratest": "^7.5", + "barryvdh/laravel-debugbar": "^4.0", + "barryvdh/laravel-ide-helper": "^3.7", + "brianium/paratest": "^7.9", "fakerphp/faker": "^1.23", - "jasonmccreary/laravel-test-assertions": "^2.5", - "laravel/pint": "^1.13", - "laravel/sail": "^1.41", + "jasonmccreary/laravel-test-assertions": "^2.9", + "laravel/pint": "^1.27", + "laravel/sail": "^1.53", "mockery/mockery": "^1.6", "nunomaduro/collision": "^8.6", - "orangehill/iseed": "^3.1", + "orangehill/iseed": "^3.8", "phpunit/phpunit": "^11.5.3", - "symfony/css-selector": "^7.2", - "symfony/dom-crawler": "^7.2" + "symfony/css-selector": "^7.4", + "symfony/dom-crawler": "^7.4" }, "autoload": { "files": [ @@ -90,6 +90,21 @@ "dev": [ "Composer\\Config::disableProcessTimeout", "npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite" + ], + "setup": [ + "composer install", + "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"", + "@php artisan key:generate", + "@php artisan migrate --force", + "npm install", + "npm run build" + ], + "test": [ + "@php artisan config:clear --ansi", + "@php artisan test" + ], + "pre-package-uninstall": [ + "Illuminate\\Foundation\\ComposerScripts::prePackageUninstall" ] }, "extra": { diff --git a/config/app.php b/config/app.php index 7eaa629ec..8dbef89b1 100644 --- a/config/app.php +++ b/config/app.php @@ -1,5 +1,5 @@ env('APP_TIMEZONE', 'UTC'), + 'timezone' => env('APP_TIMEZONE', 'UTC'), ]; diff --git a/config/filesystems.php b/config/filesystems.php index 3d671bd91..37d8fca4f 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -41,7 +41,7 @@ 'public' => [ 'driver' => 'local', 'root' => storage_path('app/public'), - 'url' => env('APP_URL').'/storage', + 'url' => rtrim(env('APP_URL', 'http://localhost'), '/').'/storage', 'visibility' => 'public', 'throw' => false, 'report' => false, diff --git a/config/sanctum.php b/config/sanctum.php index 44527d684..a6d9c5b7d 100644 --- a/config/sanctum.php +++ b/config/sanctum.php @@ -78,7 +78,7 @@ 'middleware' => [ 'authenticate_session' => Laravel\Sanctum\Http\Middleware\AuthenticateSession::class, 'encrypt_cookies' => Illuminate\Cookie\Middleware\EncryptCookies::class, - 'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class, + 'validate_csrf_token' => Illuminate\Foundation\Http\Middleware\PreventRequestForgery::class, ], ]; diff --git a/database/factories/EventFactory.php b/database/factories/EventFactory.php index 83e0616f2..e81e85eeb 100644 --- a/database/factories/EventFactory.php +++ b/database/factories/EventFactory.php @@ -3,6 +3,7 @@ namespace Database\Factories; use Carbon\Carbon; +use Illuminate\Database\Eloquent\Factories\Attributes\UseModel; use Illuminate\Database\Eloquent\Factories\Factory; /* @@ -13,15 +14,9 @@ * Idnumber begins with 2018 and adds a random and unique 4 digit number */ +#[UseModel(\App\Models\Retreat::class)] class EventFactory extends Factory { - /** - * The name of the factory's corresponding model. - * - * @var string - */ - protected $model = \App\Models\Retreat::class; - /** * Define the model's default state. */ diff --git a/database/factories/ReservationFactory.php b/database/factories/ReservationFactory.php index 4347d18be..f4824f988 100644 --- a/database/factories/ReservationFactory.php +++ b/database/factories/ReservationFactory.php @@ -4,17 +4,12 @@ namespace Database\Factories; +use Illuminate\Database\Eloquent\Factories\Attributes\UseModel; use Illuminate\Database\Eloquent\Factories\Factory; +#[UseModel(\App\Reservation::class)] class ReservationFactory extends Factory { - /** - * The name of the factory's corresponding model. - * - * @var string - */ - protected $model = \App\Reservation::class; - /** * Define the model's default state. */ diff --git a/database/migrations/2026_05_03_000001_add_expiration_index_to_cache_table.php b/database/migrations/2026_05_03_000001_add_expiration_index_to_cache_table.php new file mode 100644 index 000000000..0893b75a1 --- /dev/null +++ b/database/migrations/2026_05_03_000001_add_expiration_index_to_cache_table.php @@ -0,0 +1,30 @@ +index('expiration'); + }); + + Schema::table('cache_locks', function (Blueprint $table) { + $table->index('expiration'); + }); + } + + public function down() + { + Schema::table('cache', function (Blueprint $table) { + $table->dropIndex(['expiration']); + }); + + Schema::table('cache_locks', function (Blueprint $table) { + $table->dropIndex(['expiration']); + }); + } +}; diff --git a/package.json b/package.json index 2481ca345..b47744332 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "jquery": "~>3.5.0", "jquery-ui-bundle": "^1.12.1-migrate", "laravel-mix": "^6.0.6", - "laravel-vite-plugin": "^1.2.0", + "laravel-vite-plugin": "^2.0.0", "lodash": "^4.17.19", "popper.js": "^1.16.1", "postcss": "^8.4.47", @@ -30,7 +30,7 @@ "sass-loader": "^13.0.0", "select2": "^4.0.13", "tailwindcss": "^3.4.13", - "vite": "^6.0.11", + "vite": "^7.0.7", "vue": "^2.5.17", "vue-template-compiler": "^2.6.10", "webpack": "^5.9.0", @@ -44,5 +44,6 @@ "@babel/preset-env": "^7.15.8", "font-awesome": "^4.7.0" }, - "version": "0.0.0" + "version": "0.0.0", + "$schema": "https://www.schemastore.org/package.json" } diff --git a/phpunit.xml b/phpunit.xml index 4daaa6a9a..c3ff57b0b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -19,6 +19,9 @@ + + + diff --git a/resources/views/vendor/pagination/default.blade.php b/resources/views/vendor/pagination/bootstrap-3.blade.php similarity index 100% rename from resources/views/vendor/pagination/default.blade.php rename to resources/views/vendor/pagination/bootstrap-3.blade.php diff --git a/resources/views/vendor/pagination/simple-default.blade.php b/resources/views/vendor/pagination/simple-bootstrap-3.blade.php similarity index 100% rename from resources/views/vendor/pagination/simple-default.blade.php rename to resources/views/vendor/pagination/simple-bootstrap-3.blade.php