deladels

deladels

Member Since 2 Years Ago

Experience Points
12,110
Total
Experience

2,890 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
95
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
12,110 XP
Jul
03
1 week ago
Activity icon

Replied to 419 Page Expired On Remote Server (incorrect EncryptCookies)

Okay. Noticed you set a SESSION_COOKIE config value in your env, can you revert back to the default if possible?

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

Don't forget to clear and cache config after that and restart your server if possible.

Activity icon

Replied to 419 Page Expired On Remote Server (incorrect EncryptCookies)

@shalamnik have you also tried running php artisan config:cache and also php artisan cache:clear on your server?

Jun
15
3 weeks ago
Activity icon

Replied to Model Refresh Not Working With Tests

@bobbybouwmann Sure. I'll work around that, Thank you

Activity icon

Replied to Model Refresh Not Working With Tests

Hah, @michaloravec, got it. Works fine now.

Activity icon

Replied to Model Refresh Not Working With Tests

@tray2 updated that. Still fails.

Time: 12.61 seconds, Memory: 24.00 MB

There was 1 failure:

1) Tests\Feature\ProgramsTest::a_program_can_be_updated
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'Accelerator 2020'
+'Accelerator'
Activity icon

Replied to Model Refresh Not Working With Tests

@michaloravec it was a typo. Changed, it still fails.

Time: 12.61 seconds, Memory: 24.00 MB

There was 1 failure:

1) Tests\Feature\ProgramsTest::a_program_can_be_updated
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'Accelerator 2020'
+'Accelerator'
Activity icon

Replied to Model Refresh Not Working With Tests

@bobbybouwmann Yes they are there in my model.

class Program extends Model
{
    protected $fillable = [
        'name',
        'description',
        'cost'
    ];

}
Activity icon

Started a new Conversation Model Refresh Not Working With Tests

I am running a test to assert if a resource can be updated. However, the test keeps failing and I can't seem to figure out why.

See below my code.

ProgramTest.php

    public function a_program_can_be_updated()
    {
        $this->withoutExceptionHandling();
        $program = factory(Program::class)->create(
            [
                'name' => 'Accelerator',
                'description' => 'Accelerator Program',
                'cost' => 150
            ]
        );
       

        $this->patch(route('programs.update', $program), [
            'name' => 'Accelerator 2020',
            'description' => 'Accelerator 2020 Program',
            'cost' => 200
        ]);

        $program->refresh();
       $this->assertEquals( 'Accelerator 2020', $program->name);
        $this->assertEquals('Accelerator 2020 Program', $program->description);
        $this->assertEquals(200 , $program->cost);
    }

ProgramController.php

    public function update(Request $request, Program $program)
    {
        $program->update([
            $request->only(['name','description','cost'])
        ]);
        return redirect()->route('programs.show', $program);
    }
May
27
1 month ago
Activity icon

Replied to Jobs Failing On Heroku But Work Correctly In Local Environment

Yes. And it's empty for no reason. And I have set up the config variables for that as well in heroku

QUEUE_FAILED_DRIVER=database
Activity icon

Replied to Jobs Failing On Heroku But Work Correctly In Local Environment

Not error per se, the Jobs just failing.

2020-05-26T22:06:57.636246+00:00 app[worker.1]: [2020-05-26 22:06:57][126] Processing: App\Jobs\CertificateFileUpload
2020-05-26T22:06:57.760798+00:00 app[worker.1]: [2020-05-26 22:06:57][127] Processing: App\Jobs\CertificateFileUpload
2020-05-26T22:06:57.786592+00:00 app[worker.1]: [2020-05-26 22:06:57][128] Processing: App\Jobs\CertificateFileUpload
2020-05-26T22:06:57.797268+00:00 app[worker.1]: [2020-05-26 22:06:57][128] Failed:     App\Jobs\CertificateFileUpload

The above is from the logs. Unfortunately, it doesn't say much

May
26
1 month ago
Activity icon

Started a new Conversation Jobs Failing On Heroku But Work Correctly In Local Environment

I have some jobs set up to upload files to Digital Ocean Spaces in the background. What I noticed is that, the jobs run perfectly and the files are uploaded. But in production, I find out that the jobs are failing.

Any idea what could be going wrong? Or anyone experienced this before?

this is my job's handle method.

    public function handle()
    {
        Storage::disk('DO')->put(
            'uploads/business-registration/'.$this->certificateFileName,
            file_get_contents(
                public_path().'/storage/uploads/business-registration/'.$this->certificateFileName)
        );
        Storage::delete(public_path().'/storage/uploads/business-registration/'.$this->certificateFileName);
    }

this is my file upload service class with a handle function to process the file upload.

    public function powerPointFileUpload(Request $request) : string
    {
        $powerPointFile = $request->file('powerpoint');
        $powerPointFilename = $this->filename(
            $request->company_name, $powerPointFile
        );
        $powerPointFile->storeAs(
            'uploads/powerpoint', $powerPointFilename, 'public'
        );
        PowerPointFileUpload::dispatch($powerPointFilename);

        return $powerPointFilename;
    }

the controller method calling the file upload service

 public function store(StoreAgriBusinessInformationRequest $request, FileUploadService $fileUpload)
    {
        $uploadService = $fileUpload->handle($request);

        $registration = AgribusinessInformation::create($request->validated() + [
            'user_id' => Auth::user()->id
        ]);

        if (isset($uploadService['certificateFilename'])) {
            $registration->update([
                'attachments' => $uploadService['certificateFilename']
            ]);
        }
        
        session()->flash('success', 'Agribusiness Information Saved Successfully');
        return redirect()->route('personal-information.create');
    }

Also, I have the jobs table already migrated and changed the QUEUE_CONNECTION to database on heroku

Apr
04
3 months ago
Activity icon

Replied to Middleware For Roles Not Working As Supposed To.

@bobbybouwmann Thanks. But I have other roles and what I want to do is check if the user has a particular role. If they do, then they are redirected to the "intended" URL, if they don't have that role, then they are redirected back.

Activity icon

Started a new Conversation Middleware For Roles Not Working As Supposed To.

SO I am trying to implement some ACL in a project I am working on through middlewares but the middlewares don't seem to do the checks.

Admin Middleware:

class AdminRole
{
    public function handle($request, Closure $next)
    {
        if (Auth::user()->hasRole('Admin')) {
            return redirect()->intended();

        }

        return $next($request);
    }
}

In my controller in do this to apply the admin middleware :

    public function __construct()
    {
        $this->middleware(['auth', 'admin']);
    }

On my user model, I have this function to check for user role which gets me the correct role when I dd :

//NB:  a user has many roles

    public function hasRole($role)
    {
        if ($this->roles()->where('name', $role)->first()) {
            return true;
        }

        return false;
    }

But while testing this out, I noticed I am still able to view the page even if I am not an admin. What could be the problem?

Mar
24
3 months 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
3 months 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
3 months 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
3 months 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
3 months 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
4 months 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
4 months 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 months 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
4 months 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?