deladels

deladels

Member Since 2 Years Ago

Experience Points
11,660
Total
Experience

3,340 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
93
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 3
11,660 XP
Mar
24
6 days ago
Activity icon

Replied to Can't Seem To Do A Sum() On Results From A Groupby Results

@cliffordatcaveodotnl is there a way I can put your suggestion in a model and just call that method in the blade view directly other than writing the whole function with callbacks in the view?

Activity icon

Replied to Can't Seem To Do A Sum() On Results From A Groupby Results

@jlrdw Thank's so much for your suggestion. You have actually given me direction towards another solution/feature I am trying to implement with the suggestion. ✌

Mar
23
1 week ago
Activity icon

Replied to What Would Be The Best Approach To Track User's Activity And Show As Activity Or Timeline?

@tudosm what exactly do you mean by activity? Timeline? Do you mean something similar to Task Management where you keep track of task and show some sort of progress?

Or, you mean activity as in the actions that happen within your system? Like a user login, user updating a record etc.?

Activity icon

Started a new Conversation Can't Seem To Do A Sum() On Results From A Groupby Results

So I am trying to do a sum on a distant attribute through relationships on a collection results got from a groupBy but I always get Property[property] doesn't exist on this collection.

This is my results

Illuminate\Database\Eloquent\Collection {#820 ▼
  #items: array:3 [▼
    "Nationwide Medical Health Insurance Scheme Limited" => Illuminate\Database\Eloquent\Collection {#864 ▶}
    "Metropolitan Health Insurance Ghana Limited" => Illuminate\Database\Eloquent\Collection {#861 ▶}
    "NHIS" => Illuminate\Database\Eloquent\Collection {#818 ▼
      #items: array:1 [▼
        0 => App\PatientRecord {#1098 ▼
          #fillable: array:5 [▶]
          #connection: "mysql"
          #table: "patient_records"
          #primaryKey: "id"
          #keyType: "int"
          +incrementing: true
          #with: []
          #withCount: []
          #perPage: 15
          +exists: true
          +wasRecentlyCreated: false
          #attributes: array:6 [▶]
          #original: array:6 [▶]
          #changes: []
          #casts: []
          #dates: []
          #dateFormat: null
          #appends: []
          #dispatchesEvents: []
          #observables: []
          #relations: array:2 [▼
            "prescriptions" => Illuminate\Database\Eloquent\Collection {#993 ▼
              #items: array:2 [▼
                0 => App\Prescription {#1153 ▼
                  #fillable: array:4 [▶]
                  #casts: array:3 [▶]
                  #connection: "mysql"
                  #table: "prescriptions"
                  #primaryKey: "id"
                  #keyType: "int"
                  +incrementing: true
                  #with: []
                  #withCount: []
                  #perPage: 15
                  +exists: true
                  +wasRecentlyCreated: false
                  #attributes: array:9 [▶]
                  #original: array:9 [▶]
                  #changes: []
                  #dates: []
                  #dateFormat: null
                  #appends: []
                  #dispatchesEvents: []
                  #observables: []
                  #relations: array:1 [▼
                    "medicine" => App\Medicine {#1178 ▼
                      #fillable: array:10 [▶]
                      #casts: array:3 [▶]
                      #connection: "mysql"
                      #table: "medicines"
                      #primaryKey: "id"
                      #keyType: "int"
                      +incrementing: true
                      #with: []
                      #withCount: []
                      #perPage: 15
                      +exists: true
                      +wasRecentlyCreated: false
                      #attributes: array:13 [▼
                        "id" => 1
                        "category_id" => 1
                        "supplier_id" => 1
                        "name" => "Amoxicillin"
                        "reorder_point" => 20
                        "minimum_level" => 15
                        "insurance_cover" => "0.20"
                        "units" => 491
                        "selling_price" => "4.51"
                        "expiration" => "Default"
                        "expiry_date" => "2027-01-13"
                        "created_at" => "2020-01-07 23:53:39"
                        "updated_at" => "2020-03-14 09:50:44"
                      ]
                      #original: array:13 [▶]
                      #changes: []
                      #dates: []
                      #dateFormat: null
                      #appends: []
                      #dispatchesEvents: []
                      #observables: []
                      #relations: []
                      #touches: []
                      +timestamps: true
                      #hidden: []
                      #visible: []
                      #guarded: array:1 [▶]
                    }
                  ]
                  #touches: []
                  +timestamps: true
                  #hidden: []
                  #visible: []
                  #guarded: array:1 [▶]
                }
                1 => App\Prescription {#1154 ▶}
              ]
            }
            "prescriptionpayments" => App\PrescriptionPayment {#1207 ▶}
          ]
          #touches: []
          +timestamps: true
          #hidden: []
          #visible: []
          #guarded: array:1 [▶]
        }
      ]
    }
  ]
}

I am trying to do a sum on the selling_price of the medicines collection so I get something like NHIS->$200 total medicines

Controller :

public function dashboard()
    {

        $records = PatientRecord::with(['prescriptions.medicine', 'prescriptions', 'prescriptionpayments'])
            ->has('prescriptionpayments')
            ->get();

        $groupedRecords = $records->groupBy('type');
        
        return view('accounts.cash-office.dashboard',
            compact( 'groupedRecords'));
    }

My View ;

<div class="row mt-4 mb-5">
                @foreach ($groupedRecords as $key => $record)
                    <div class="col-lg-4 col-md-12 col-sm-12 mb-2">
                        <div class="card shadow payment-card">
                            <div class="card-body">
                                <h6 class="card-title">
                                    {{ $key }}
                                </h6>
                                <h5 class="font-weight-bold pt-3">
                                    GH¢ {{ number_format($payments->prescriptions->sum('medicine.selling_price'), 2) }}
                                </h5>
                            </div>
                        </div>
                    </div>
                @endforeach
            </div>
Activity icon

Replied to How To Go About Efficiently Implementing A Resource/time Consuming Event Like Online Payment.

Riigghhtt @bobbybouwmann thank you so much. I will wrap my head around that and see how I'd go about it.

@shez1983 Oh Okay. Thanks for you input.

Mar
22
1 week ago
Activity icon

Replied to How To Go About Efficiently Implementing A Resource/time Consuming Event Like Online Payment.

Thanks @snapey.

I'll reach out to the providers.

With respect to making each transaction independent, how do I achieve this? Using Jobs/Queues?

Activity icon

Replied to How To Go About Efficiently Implementing A Resource/time Consuming Event Like Online Payment.

@bobbybouwmann Oh okay. Understood. My first instinct was to read about jobs and see how they fit. but I wasn't soo sure if I should go that way

Activity icon

Replied to How To Go About Efficiently Implementing A Resource/time Consuming Event Like Online Payment.

@bobbybouwmann Thanks.

So there's a form the user fills out with their details. those details are then sent to a third-party payment provider that handles payment processes.

so when the request is successful, the user is prompted on their phone to authorize a payment.

and between that time I have to wait for a p[ayment successful or failure response from the payment provider.

I hope this is clear enough

Activity icon

Started a new Conversation How To Go About Efficiently Implementing A Resource/time Consuming Event Like Online Payment.

I currently have a payment process on my web application I am building. Currently, it works fine. but I have had some thoughts recently. what if I hit a peak point.

When making the payment online, the user is prompted to enter a code to authorize a transaction.

even with the current implementation, it gets slow sometimes and I get timeouts from the payment service (through an API).

how can I go about this? so the application doesn't become very slow?

I am Implementing this in laravel.

Mar
20
1 week ago
Activity icon

Replied to 404 Not Found When Get Response From API

Thanks very much, guys. Works now

Activity icon

Started a new Conversation 404 Not Found When Get Response From API

I am making a request to a payment API. When this is done, the payment provider attaches some values as a response after a call to the API.

this is my route in web.php

Route::get('payments/confirmation/{response}/', '[email protected]')->name('payments.confirm');

this is the response:

http://127.0.0.1:8000/payments/confirmation/?status=approved&code=000&reason=Transaction successful!&transaction_id=e19

now I am trying to get the response data but I keep getting a 404 Not found error after a redirect to the:

payments/confirmation route.

here is my controller, I am just doing a dd for now:

 public function confirm(Request $request, $response)
    { 
        dd($response);
	
}

what could be the issue?

Mar
12
2 weeks ago
Activity icon

Awarded Best Reply on Trying To Do A SUM On A Collection Result From A GroupBy

@jlrdw Thanks for the suggestion. I will definitely take a look at it for more knowledge.

Finally, I got it to work by restructuring my query.

Thank you all.

Did this in the controller:

$todayPayments = PrescriptionPayment::whereDate('created_at', Carbon::today())

                        ->with('record')

                        ->get();

$groupPaymentRecords = $todayPayments->groupBy('record.type');

and got the sum like this in my view:

@foreach ($groupPaymentRecords as $key => $payments)
          <div class="col-lg-4 col-md-12 col-sm-12 mb-2">

                <div class="card shadow payment-card">
                    <div class="card-body">
                        <h6 class="card-title pharmacy-dashboard-card-title 
				font-weight-bold">
                            {{ $key }}
                        </h6>
                        <span class="font-weight-bold pt-3">
                            GH¢ {{ number_format($payments->sum('amount'), 2) }}
                        </span>
                    </div>
                </div>

          </div>
@endforeach
Activity icon

Replied to Trying To Do A SUM On A Collection Result From A GroupBy

@jlrdw Thanks for the suggestion. I will definitely take a look at it for more knowledge.

Finally, I got it to work by restructuring my query.

Thank you all.

Did this in the controller:

$todayPayments = PrescriptionPayment::whereDate('created_at', Carbon::today())

                        ->with('record')

                        ->get();

$groupPaymentRecords = $todayPayments->groupBy('record.type');

and got the sum like this in my view:

@foreach ($groupPaymentRecords as $key => $payments)
          <div class="col-lg-4 col-md-12 col-sm-12 mb-2">

                <div class="card shadow payment-card">
                    <div class="card-body">
                        <h6 class="card-title pharmacy-dashboard-card-title 
				font-weight-bold">
                            {{ $key }}
                        </h6>
                        <span class="font-weight-bold pt-3">
                            GH¢ {{ number_format($payments->sum('amount'), 2) }}
                        </span>
                    </div>
                </div>

          </div>
@endforeach
Activity icon

Replied to Trying To Do A SUM On A Collection Result From A GroupBy

@ftiersch thanks for your snippet. actually needed that as well.

But what I want is to do a sum of the group items.

for instance, this is what I get from my group by:

Illuminate\Database\Eloquent\Collection {#756 ▼
  #items: array:2 [▼
    "Metropolitan Health Insurance Ghana Limited" => Illuminate\Database\Eloquent\Collection {#764 ▶}
    "Cash" => Illuminate\Database\Eloquent\Collection {#763 ▶}
  ]
}

so I want to do a sum on the keys (Cash, metro Insurance etc.)

currently doing that I my view like this

<div class="row mt-4 mb-4">
              @foreach ($groups as $key => $group)
              {{-- {{ dd($group) }} --}}

              @foreach ($group as $record)
                
              @endforeach
              <div class="col-lg-4 col-md-12 col-sm-12 mb-2">
                  <div class="card shadow payment-card">
                      <div class="card-body">
                          <h6 class="card-title pharmacy-dashboard-card-title font-weight-bold">
                              {{ $key }}
                          </h6>
                          {{-- <span class="card-subtitle mb-2 text-muted font-weight-bold">
                        Total for today
                    </span> --}}
                          <span class="font-weight-bold pt-3">
                              GH¢ {{ number_format($record->prescriptions->sum('prescriptionPayment.amount'), 2) }}
                          </span>
                      </div>
                  </div>
              </div>
              @endforeach
          </div>

But for some reason, I don't get the totals correctly. For instance, the sum for the cash keys is done twice if there are two results in that group.

Mar
11
2 weeks ago
Activity icon

Replied to Trying To Do A SUM On A Collection Result From A GroupBy

@jlrdw Thank You.

I'm working directly with a pharmacy.

Activity icon

Replied to Trying To Do A SUM On A Collection Result From A GroupBy

@ftiersch still doesn't give me the sum. I get 0

Activity icon

Replied to Trying To Do A SUM On A Collection Result From A GroupBy

@ftiersch if I sum before I group then I can't group by the type. I get a call to a member function groupBy() on int

Activity icon

Replied to Trying To Do A SUM On A Collection Result From A GroupBy

@rin4ik Thanks, but it wouldn't work cuz I am pretty sure I will get a prescription is not defined on this collection instance error

Activity icon

Started a new Conversation Trying To Do A SUM On A Collection Result From A GroupBy

So I need to do get some results from my database and after do a group by. Later, I needed to do a sum of the amounts in the database table. What I have now is just returning 0 even tho there are amounts in the table, Any help?

Below is my current code.

Code used to retrieve the records

public function index()
    {
        $records = PatientRecord::with(['patient', 'prescriptions.prescriptionPayment', 'prescriptions.medicine'])

                    ->has('prescriptions.prescriptionPayment')
        
                    ->get();
        $groups = $records->groupBy('type');

        dd($groups->sum('prescriptions.prescriptionPayment.amount')); 

        return view('accounts.prescriptions.payments', compact('records'));
    }
Mar
03
3 weeks ago
Activity icon

Replied to Undefined Variable Error When Variableis Called Outside Foreach Loop.

@sinnbeck Absolutely. Actually ended up doing that. Thanks

Mar
02
4 weeks ago
Activity icon

Replied to Laravel Nova - Digitalocean Spaces Permissions

@devfrey Thanks very much. I needed this today. Still works flawlessly on Laravel 6.

Feb
28
1 month ago
Activity icon

Replied to Undefined Variable Error When Variableis Called Outside Foreach Loop.

@sinnbeck Alright. Most likely I'd resort to handling them separately. just felt like that will be extra lines of code.

Activity icon

Replied to Undefined Variable Error When Variableis Called Outside Foreach Loop.

@sinnbeck I have shown my form. You are seeing one file because I only filled one of the file input.

Activity icon

Replied to Undefined Variable Error When Variableis Called Outside Foreach Loop.

@sinnbeck The output

Illuminate\Http\UploadedFile {#342 ▼
  -test: false
  -originalName: "mybusinesscert.pdf"
  -mimeType: "application/json"
  -error: 0
  #hashName: null
  path: "C:\xampp\tmp"
  filename: "phpE5B9.tmp"
  basename: "phpE5B9.tmp"
  pathname: "C:\xampp\tmp\phpE5B9.tmp"
  extension: "tmp"
  realPath: "C:\xampp\tmp\phpE5B9.tmp"
  aTime: 2020-02-28 09:58:52
  mTime: 2020-02-28 09:58:52
  cTime: 2020-02-28 09:58:52
  inode: 0
  size: 263705
  perms: 0100666
  owner: 0
  group: 0
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
  linkTarget: "C:\xampp\tmp\phpE5B9.tmp"
}

And you are right the dd within the loop is never hit. Lol

Activity icon

Replied to Undefined Variable Error When Variableis Called Outside Foreach Loop.

@snapey this is how my form looks like

<form action="{{ route('agribusiness-information.store') }}" method="POST" enctype="multipart/form-data">
    @csrf
    <div class="form-group">
        <label for="">Name of Company</label>
        <input type="text" name="company_name" class="form-control" required>
    </div>
    <div class="form-group">
        <label for="exampleFormControlFile1">
            Upload Company Registration Certificate
        </label>
        <input type="file" name="attachments[]" class="form-control-file" required>
    </div>
    <div class="form-group">
        <label for="">
            Upload a 2 slide PowerPoint about your agribusiness
        </label>
        <input type="file" name="attachments[]" class="form-control-file">
    </div>
    <div class="form-group">
        <button class="btn btn-primary btn-block">SAVE PROFILE & CONTINUE</button>
    </div>
</form>
Activity icon

Replied to Undefined Variable Error When Variableis Called Outside Foreach Loop.

@sinnbeck i get to see the files when i do dd($request->attachments); so the files/attachments are coming in from the request.

Activity icon

Replied to Undefined Variable Error When Variableis Called Outside Foreach Loop.

Then I just get an empty array when I dd. tried that.

Activity icon

Replied to Undefined Variable Error When Variableis Called Outside Foreach Loop.

@sinnbeck Did that. Just didn't add it to the code snippet I posted.

Activity icon

Replied to Free Email And Notification

@noblemfd I don't think there are free email service providers out there apart from google. the are others, most of which are relatively cheap like Zoho Mail and co.

Activity icon

Started a new Conversation Undefined Variable Error When Variableis Called Outside Foreach Loop.

So I have a form with two file inputs which I want to work with, Files are stored in stored and files names are saved in the database.

I am trying to put the file names in an array before I save it to the database. While trying to do this I get an undefined variable name.

if ($request->hasFile('attachments')) {
    
         $registrationFiles = [];
    
            foreach ($request->attachments as $file) {

                $filename = $file->getClientOriginalName();
                $file->storeAs('public/files/uploads', $filename);
                $registrationFiles[] = $filename;

            }
} 
    
    dd($registrationFiles);

When I do add, it says undefined variable '$registrationFiles'. I wasn't sure why this was happening so I replicated something like the snippet below which worked.


$myArray = [ 1, 4, 5, 6];

        foreach ($myArray as $value) {
            # code...
            $newValues[] = $value + 1;
          
        }

 dd($newValues);

what am I doing wrong?

Nov
15
4 months ago
Activity icon

Replied to Database Design / Schema For A Vet CLinic's Laboratory.

@fylzero I wrapped my head around your suggestion. But the issue here is that because every lab test is unique, the report content will be unique as well. So how exactly would you go about storing that content? What data type are you going to use? probably JSON?

@jlrdw ALright Sure. I will. Thanks for the extra tip.

Nov
14
4 months ago
Activity icon

Replied to Database Design / Schema For A Vet CLinic's Laboratory.

Thank You @fylzero. I will definitely wrap my head around your suggestion and come back with feedback.

Activity icon

Awarded Best Reply on Retrieving Records With HasManyThrough() Relationship

Sure. But that's Just part One of the problem.

For the other part, for whoever stumbles on this in the future.

You could do something like:


$post->user->country (as per the example in the laravel docs)

or with my example above, I was able to do this

$vitals->record->patient->lastname;

Activity icon

Replied to Retrieving Records With HasManyThrough() Relationship

Sure. But that's Just part One of the problem.

For the other part, for whoever stumbles on this in the future.

You could do something like:


$post->user->country (as per the example in the laravel docs)

or with my example above, I was able to do this

$vitals->record->patient->lastname;

Activity icon

Started a new Conversation Database Design / Schema For A Vet CLinic's Laboratory.

So I am currently working a small project for a Vet Clinic in my local community. The project in a nutshell simply involves transforming their operations into a digital experience from the good old paperwork. I decided to split the project into phases Now, I am at a phase where I need to create an interface where the Vets can fill out a form in order to record the results of a lab test.

I have been giving this a thought for the past 24 hours but the solutions I come up with I am certain aren't the best at all.

so the issue is that the Vet Clinic has a lab department that carries out or performs quite a number of types of lab tests.

Right now. From the data, I am working with, there are categories of Lab Test, Under these categories, you have different types of Lab Test (A category can have multiple types of test).

The issue is that every type of test is unique and comes with its own format for the way the reports are generated.

Any suggestions on how I can go about this? both Frontend and backend? (On the frontend I know I am going to have to find a way to present different forms for each test result type).

Nov
12
4 months ago
Activity icon

Replied to Retrieving Records With HasManyThrough() Relationship

@aruszala Did that so that side works now. Thanks

Nov
11
4 months ago
Activity icon

Started a new Conversation Retrieving Records With HasManyThrough() Relationship

In my application, I have three models that are related through one model.

Patient Model:
-id
-name
-address

PatientRecord Model
-id
-patient_id
-created_at

Vitals Model
-id
-record_id
-blood_pressure

So as is, the patient has many records (patient_records) and thus has many vitals through the patient record,

now:

  1. I am trying to get all patients along with their records. As demonstrated in the laravel docs :
$country->posts should get all posts belonging to a country.

This doesn't work for me when I do:

$patient->vitals

  1. Is there a way I can do an inverse querying?

for example, if I want to get a patient's last and first name

$vitals->patient->lastname

Patient Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Patient extends Model
{
    protected $fillable = [
        'patientID',
        'firstname',
        'lastname',
        'other_names',
        'image',
        'email',
        'address',
        'phone',
        'alt_phone',
        'dob',
        'gender',
        'marital_status',
        'blood_group',
        'insurance_id',
        'ssn'
    ];


    public function records()
    {
        return $this->hasMany(PatientRecord::class);
    }

    public function vitals()
    {
        return $this->hasManyThrough(Vitals::class, PatientRecord::class);
    }


    public function setLastNameAttribute($value)
    {
        $this->attributes['lastname'] = ucfirst($value);
    }

    public function setFirstNameAttribute($value)
    {
        $this->attributes['firstname'] = ucfirst($value);
    }

    public function setOtherNamesAttribute($value)
    {
        $this->attributes['other_names'] = ucwords($value);
    }
}

PatientRecord Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class PatientRecord extends Model
{
    protected $fillable = [
        'record_number',
        'patient_id'
    ];

    public function patient()
    {
        return $this->belongsTo(Patient::class);
    }

    public function vitals()
    {
        return $this->hasOne(Vitals::class);
    }

}

VItals Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Vitals extends Model
{
    protected $fillable = [
        'record_id',
        'blood_pressure',
        'pulse',
        'respiratory',
        'temperature',
    ];

    public function record()
    {
        return $this->belongsTo(PatientRecord::class);
    }

}
Activity icon

Started a new Conversation How To Generate Unique Random Numbers

I want to generate unique random strings of numbers.

As per my research, rand() and mt_rand() both repeat the numbers at a certain point.

I have actually implemented rand() and mt_rand() and I have noticed for myself the repetition already.

does random_int() produce unique numbers()?

Thank You

Nov
02
4 months ago
Activity icon

Replied to Best Way To Approach Payment Gateway?

@daugaard47 I haven't used stripe myself before. should the need arise? I'd definitely reach out.

Activity icon

Awarded Best Reply on Middleware Not Redirecting To Specified Route.

Yeah, my routes existed.

Finally Managed to get it working by extracting the Password Changing Functionality to another class on its own. Works perfectly now.

Thank you all.

@snapey @sinnbeck @muath

Activity icon

Replied to Middleware Not Redirecting To Specified Route.

Yeah, my routes existed.

Finally Managed to get it working by extracting the Password Changing Functionality to another class on its own. Works perfectly now.

Thank you all.

@snapey @sinnbeck @muath

Activity icon

Replied to Middleware Not Redirecting To Specified Route.

@snapey yes. it's to be used only by authenticated users.

Opening the dev tools, I noticed it's returning a 302 status code for both the password-change route and the intended route being protected by the middleware. So it seems not to know where exactly to redirect to or something.

Activity icon

Replied to Middleware Not Redirecting To Specified Route.

Yeah it hits.

returns the request with the user object and its attributes. everything is there.

Activity icon

Replied to Middleware Not Redirecting To Specified Route.


 public function showPasswordChangeForm()
    {
        return view('auth.passwords.password-change');
    }

that's the content of the showPasswordChangeForm, it just returns the view to change the password.

Activity icon

Replied to Middleware Not Redirecting To Specified Route.

@sinnbeck

Tried this already


if (!$request->user()->status)

It didn't work. Still redirecting to the home page.

Activity icon

Replied to How To Multiple Show Data In Dropdown List . Laravel 6

Another way to have done it.

since you have already defined an accessor in your model.

you could just do something like this

@foreach($users as $user )

  <option value="{{ $user->id (or something) }}">

    {{ $user->name_date }} 

</option>

@endforeach

Activity icon

Started a new Conversation Middleware Not Redirecting To Specified Route.

So I am trying to use middleware to check whether the user account that is been used to log in is active or not.

the check seems to happen alright but it redirects to the homepage instead of a specified named route.

MIddleware:

class CheckLeaderAccountStatus
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        if ($request->user()->status === false) {

    //If true, the  account is active, if false it's inactive
        
            return redirect()->route('change-password');
        }

        return $next($request);

    }
}

Routes file:

Route::prefix('leader')->group( function() {

    Route::get('/login', 'Auth\[email protected]')->name('leader.login');

    Route::get('/password-change', 'Auth\[email protected]')
    
            ->name('change-password');
            
    Route::post('/login', 'Auth\[email protected]')->name('leader.login.submit');

    Route::get('/logout', 'Auth\[email protected]')->name('leader.logout');

    Route::get('/', '[email protected]')->name('leader');

});

I can't seem to figure out why it isn't redirecting to the specified route.

If an account is active tho, it works and the user is redirected to their intended route.

Thanks for the help.