ehabafia

ehabafia

Software Engineer at Playstones

Member Since 6 Years Ago

Mississauga, ON

Experience Points
96,960
Total
Experience

3,040 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
1092
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 20
96,960 XP
Sep
30
3 weeks ago
Activity icon

Awarded Best Reply on Laravel Make A Call To A Phone Through Twilio

I got the problem, thank you for your support.

The problem was when I use the code:

 $request->file_name->store('notifications', 'public');

Laravel is considering that the file is not mp3, instead it's mpga, so it uploaded it as mpga.

I used instead:

$file = $request->file_name;
$file->move(public_path('storage/notification)', $filename);

it worked perfectly.

Activity icon

Replied to Laravel Make A Call To A Phone Through Twilio

I got the problem, thank you for your support.

The problem was when I use the code:

 $request->file_name->store('notifications', 'public');

Laravel is considering that the file is not mp3, instead it's mpga, so it uploaded it as mpga.

I used instead:

$file = $request->file_name;
$file->move(public_path('storage/notification)', $filename);

it worked perfectly.

Activity icon

Replied to Laravel Make A Call To A Phone Through Twilio

The only difference I can see is that if I put the URL of the mp3 file of the local it plays it, while if I put the production URL it forces me to download it.

So, how can I make the file in the production to be played if I put the URL in the browser?

Activity icon

Replied to Laravel Make A Call To A Phone Through Twilio

it says that it can't while the file is there I checked the URL and it's correct and everything seems to be correct. Not sure why.

Activity icon

Started a new Conversation Laravel Make A Call To A Phone Through Twilio

I am wondering if someone can help me here for a Twilio Call, here is the code:

$lead = Lead::findOrFail($request->id);
        $notification = NotificationSetting::find($request->prc);

        $response = new VoiceResponse();
        $response->play(url('storage/'.$notification->voice_call), ['loop' => 10]);

        $client = new Client(config('mtc.twilio.sid'), config('mtc.twilio.token'));

        $call = $client->account->calls
               ->create('+1'.$lead->phone, // to
                        config('mtc.twilio.from'), //from
                        ['twiml' => $response]
               );

The problem is when I call the code through ngrok it works fine, but when I using through forge.laravel.com, it doesn't. It calls my phone but it tells me that there is an error. While when I use my local, it works just fine.

Any idea why?

Thank you,

Sep
09
1 month ago
Activity icon

Replied to How To Run Scheduler On First Business Day Of A Month?

I am talking about the first business day of the month including regional public holidays for sure, But as far as I know, the cimixin/business-day does take care of all kinds of non-business days.

Activity icon

Replied to How To Run Scheduler On First Business Day Of A Month?

Would I be able to use at to choose the time like this:

	$schedule->command('inspire')->when(function () {
            return \Carbon\Carbon::now()->isSameDay($this->findFirstBusinessDay());
        })->at('08:00');

Thank you,

Activity icon

Started a new Conversation How To Run Scheduler On First Business Day Of A Month?

Hi there,

I want to run a schedule command every first business day of the month. There are lots of options on how when to schedule something, but no option to run something on the first business day of the month - at least I cannot find it.

I found something similar but not exact and doesn't work no matter what I do. So, I hope you can help

	$schedule->command('inspire')->when(function () {
            return \Carbon\Carbon::now()->endOfMonth()->isToday();
        });

I am using cmixin/business-day so, I thought of something similar to:

$schedule->command('mtc:flex_refund')->when(function () {
            return \Carbon\Carbon::now()->firstOfMonth()->isBusinessDay();
        });

But no luck :(

Thanks,

Sep
07
1 month ago
Activity icon

Awarded Best Reply on I Am Looking For A Sum With Condition

I got it, the answer is:

public function getTotalOutstandingAttribute()
    {
        return $this->finances->where('status', '>', 59)->sum('total_outstanding');
    }
Activity icon

Replied to I Am Looking For A Sum With Condition

I got it, the answer is:

public function getTotalOutstandingAttribute()
    {
        return $this->finances->where('status', '>', 59)->sum('total_outstanding');
    }
Activity icon

Started a new Conversation I Am Looking For A Sum With Condition

Hi,

I am looking for a sum with the condition:

this is in the finance model:

    public function getTotalOutstandingAttribute()
    {
        return $this->amount_borrowed + $this->total_penalties() - $this->total_payments();
    }

and in the borrower model which the borrower hasMany finances

    public function getTotalOutstandingAttribute()
    {
        return $this->finances->sum('total_outstanding');
    }

I am looking for a way to have a conditional sum('total_outstanding'). This one is giving me a total of totals with no problem, but I am looking to add a condition like for only the finances that their status is 'active' for instance.

Thank you,

Sep
02
1 month ago
Activity icon

Replied to I Am Trying To Get Total Amount Conditional And Per Month

how about the credit and debit?

Activity icon

Started a new Conversation I Am Trying To Get Total Amount Conditional And Per Month

Hello Laracasts,

I am trying to get a sum amount per month through created_at, these amounts are all positives but they have another field type which is either debit or credit.

So, either I need one sum but by flipping the sign of the debit to be negative and then add the amount together or by having sum fields one for credit and one for debit. These fields need to be per month.

so, the end result should be January or 1, 2020 - amount = 2000 ... or January or 1, 2020 - type = credit - total_credit = 3000 - type = debit - total_debit = 1000 ...

Something in that range.

    public function monthly_totals()
    {
        return $this->hasMany(Transaction::class)
            ->select('created_at', 'sum(amount)')
            ->groupBy('MONTH(created_at)', 'YEAR(created_at)')
            ->get();
    }

That is not even close to the solution, but kind of start.

Thank you so much for your support.

Sep
01
1 month ago
Activity icon

Replied to Variable Constant

@jlrdw No, in my case what's after Finance is a constant. Here is an example:

class Finance extends Model
{
    // Messages
    public const FINANCE_ISSUED          = 'Finance Issued';
    public const DUE_DILIGENCE_FEE       = 'Due Diligence Fee';
    public const SETUP_FEE               = 'Setup Fee';
}

So, from another class:

use App\Finance;

class AchAgreementService
{
    public Finance $finance;

    public function __construct(Finance $finance)
    {
        $this->finance = $finance;
    }


    public function getFees($string)
    {
        ...
        dd(Finance::$string);
    }
}
Activity icon

Replied to Variable Constant

@jlrdw The problem is that the $string is a variable that I am getting, so I need to call the constant according to the value of $string.

Activity icon

Replied to Variable Constant

@automica Yes, it is giving undefined variable Finance::$string

Regarding the namespace, I did use it at the top, and just to give you a hint, when I tried to dd(Finance::SETUP_FEE); I can see the result which is Setup Fee

So, I am not sure, it seems that PHP doesn't accept a variable constant.

Activity icon

Replied to Variable Constant

@geordiejackson I assumed like you that it should work that way but I don't know why it didn't.

@automica That become so, much of a hassle. I don't think it's worth it.

Aug
31
1 month ago
Activity icon

Replied to Variable Constant

Thank you very much, I checked it, but none of the threads talking about a variable constant. What I am trying to get is different constants based on variables.

Finance::$variable;
Activity icon

Started a new Conversation Variable Constant

Hello everyone,

Not sure if this is something allowed in PHP. I am looking to have a variable constant

	$string = 'SETUP_FEE';

	dd(Finance::$string);

This is basically what I am trying to do, is to get the class constant value of the string. This is now getting an error, is there a way to make it or this is not allowed by the PHP nature.

Thank you,

Aug
30
1 month ago
Activity icon

Replied to Where In SubQuery

Thank you, that's exactly it.

Activity icon

Replied to Where In SubQuery

I was able to filter them after query, but I am sure that there is a better way to have it inside the query scopre

$filtered = $newBorrowers->filter(function($borrower){
            return $borrower->finances_count > 0;
        });
Activity icon

Replied to Where In SubQuery

This is great, thank you. But what I am looking for is not the count. I want to know the borrowers that are not having finance, which is their count is zero.

I am wondering how can I have a where condition to eliminate the count > 0.

Activity icon

Started a new Conversation Where In SubQuery

Hello Laracasts,

I am creating a subQuery and trying to put a condition in the subQuery itself but it's giving me an error. Here is an example:

        $newBorrowers = Borrower::newBorrowers()->get();
    public function scopeNewBorrowers($query)
    {
        return $query->where('login_id', '!=', null)->addSelect([
                'finance_count' => function ($q) {
                    $q->from('finances')
                        ->select(\DB::raw('count(id)'))
                        ->whereColumn('borrowers.id', 'finances.borrower_id');
                }
            ]);
    }

The condition I am trying to have is I want to get the newBorrowers who got finance_count = 0;

So, any borrower that doesn't have any finances is what I need to get.

Is there a good, or better what than what I am doing here?

Thank you,

Aug
21
2 months ago
Activity icon

Replied to SubQuery For Summing A Transactions

Thank you all.

Activity icon

Replied to SubQuery For Summing A Transactions

I think I did it :)

        static::addGlobalScope('outstanding_amount', function(Builder $builder){
            $builder->addSelect([
                'outstanding_amount' => function ($q) {
                    $q->from('trans_transactions_details')->select(\DB::raw('SUM(amount)'))->whereColumn('finance_id', 'finances.id');
                }
            ]);
        });

Is this a good solution or there is any better one.

Activity icon

Replied to SubQuery For Summing A Transactions

Thank you so much for your reply.

Now it works as Finance::outstandingAmount()->get(1);

is there a way that I can include it inside each Finance, so that if I call:

$finance = Finance::all();

will get all the loans with that outstanding_amount included in the result set?

Thank you,

Activity icon

Started a new Conversation SubQuery For Summing A Transactions

Hello everyone, I am looking for a simple (I hope :) ) thing which I have several loans each loan has several transactions (payments), I need to add a field in the loan resultset called amounts_paid.

<?php namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

class Finance extends Model
{

    public function transactions()
    {
        return $this->hasMany(Transaction::class);
    }
}

and the Transaction class looks like:

<?php namespace App;

use Illuminate\Database\Eloquent\Model;

class Transaction extends Model
{
    public function finance()
    {
        return $this->belongsTo(Finance::class);
    }
}

So, I was thinking of having something like this:

    public function scopeOutstandingAmount(Builder $builder)
    {
        return $builder->addSelect([
            'outstanding_amount' => Transaction::sum('amount')
                ->whereColumn('finance_id', 'finance.id')
                ->first()
        ]);
    }

For some reason, it's not working. Can someone please tell me what is the problem and how can I solve it.

Thank you so much for you all.

Aug
14
2 months ago
Activity icon

Replied to Id Not Found, I Am Trying To Get It By Slug

Cool,

It happens. :)

Activity icon

Replied to Id Not Found, I Am Trying To Get It By Slug

I was able to make it work by adding the following code:

$setting->fill($data)->save($data);

While, when I make it directly like:

$settings->update($data);

it doesn't work in fact when I dd($this->isDirty()); it return false

Activity icon

Replied to Id Not Found, I Am Trying To Get It By Slug

But now the update is not working:

	$settings->update($data);

still giving an error that id is not defined :(

Activity icon

Replied to Id Not Found, I Am Trying To Get It By Slug

the route list is showing:

notifications/settings/{setting}/edit

I tried your code and BINGO, it worked.

I think because the name route is setting then I have to call my variable $setting and not $settings.

Thank you so much.

Activity icon

Replied to Id Not Found, I Am Trying To Get It By Slug

This method is not working:

    /**
     * Show the form for editing the specified resource.
     *
     * @param NotificationSetting $settings
     * @return Application|Factory|Response|View
     */
    public function edit(NotificationSetting $settings)
    {
        return view('notifications.settings.edit', compact('settings'));
    }

While this method worked:

    /**
     * Show the form for editing the specified resource.
     *
     * @param $slug
     * @return Application|Factory|Response|View
     */
    public function edit($slug)
    {
        $settings = NotificationSetting::whereSlug($slug)->first();

        return view('notifications.settings.edit', compact('settings'));
    }
Activity icon

Replied to Id Not Found, I Am Trying To Get It By Slug

Correct, but it's giving empty array, while there is a record and was able to get it by the search:

$settings = NotificationSetting::whereSlug($slug)->get();

but directly for some reason, it's getting an empty array;

Activity icon

Replied to Id Not Found, I Am Trying To Get It By Slug

Here is the route:

    Route::resource('/notifications/settings', 'NotificationSettingController');

so, when I am trying to go to the edit route: http://domain.test/slug-slug/edit it's giving the error that there is not settings.id field is not found.

Activity icon

Started a new Conversation Id Not Found, I Am Trying To Get It By Slug

Hi,

For some reason the controller couldn't get the slug instead of id, I added this to the model

    public function getRouteKeyName()
    {
        return 'slug';
    }

so, when I call php Setting::all(); I am still getting an error that settings.id is not found.

Any thoughts?

Aug
08
2 months ago
Activity icon

Commented on Let's Test The Laracasts Login Modal

This is really cool, but I read that in Laravel 8.x they are planning to have Pest to be the official Laravel testing, which I wish they add this as well for acceptance testing.

Aug
05
2 months ago
Activity icon

Replied to Login A User To Confirm

Actually, yours worked, but once every 3 hours while the client wants it to be every time he wants to submit a transaction.

The cool thing about the password rule is that you just add it to the validation and if the password is not correct the form will give an error and it will not be processed.

Thank you,

Activity icon

Awarded Best Reply on Login A User To Confirm

Actually, this answer didn't work perfectly as expected, instead here is the correct answer that works perfectly.

just add a field into your form that needs to confirm the password and add a form validation with the following rules:

"password" => "required|password"

this way if the field was empty or the password provided wasn't matching the requested will be directed back to the /create again with the proper error.

Thank you,

Activity icon

Replied to Login A User To Confirm

Actually, this answer didn't work perfectly as expected, instead here is the correct answer that works perfectly.

just add a field into your form that needs to confirm the password and add a form validation with the following rules:

"password" => "required|password"

this way if the field was empty or the password provided wasn't matching the requested will be directed back to the /create again with the proper error.

Thank you,

Aug
02
2 months ago
Activity icon

Replied to Login A User To Confirm

Most of the banks I dealt with is outside Canada, but even in Canada TD Canada Trust does that as well.

Activity icon

Replied to Login A User To Confirm

@jlrdw You could check the best answer to see if this is something common or not.

Activity icon

Replied to Login A User To Confirm

@jlrdw I am not sure about your experience in banks. But customers are always right. If that's what the customer wants then we have to do what they ask for not what we think is correct.

When you deal with money then everything is possible. So the admin could leave his terminal opens, and someone could come and process a transaction. I worked more than 10 years in banks, they always have some kind of confirmation to do before processing any transaction.

Thanks for your effort anyway.

Activity icon

Replied to Login A User To Confirm

I think you didn't get my point.

The admin is logged in, and he is going to make a transaction. So, before the system process the transaction I need to make sure that the user is the same user.

I want to make sure that the user didn't leave his system open and someone else is who is trying to make the transaction. So, I need him to put his username and password again before processing the transaction to make sure that he is the admin. Once he did put his correct username and password and the system confirmed it, then the transaction will be processed.

I hope that this explanation clarify it.

Thank you,

Activity icon

Started a new Conversation Login A User To Confirm

Hi,

I am looking to make the user login while he/she is logged in already to confirm that he is the user.

It's basically, there is a sensitive action the admin is going to do. So, I need to confirm that the logged-in user is the correct admin, therefore, I need him to log in again through a modal or so to confirm that he is allowed to take the action.

Jul
25
3 months ago
Activity icon

Replied to What Is The Use Of Defer In The App.js

Thank you, that helped.

Activity icon

Started a new Conversation What Is The Use Of Defer In The App.js

Hello, Laravel community.

I am trying to use select2.js library but for some reason, it refuses to work.

After allot of tries I just moved the word defer from the link of the app.js, it worked just fine.

    <script src="{{ mix('js/app.js') }}" defer></script>
this worked
    <script src="{{ mix('js/app.js') }}"></script>

My question what would the defer will do? and would that affect the Vue components that I have in my app?

Thank you,

Activity icon

Replied to Array Validation Rule And Old()

And how about the rule itself, would it be due_diligence_fee[fee] or due_diligence_fee.fee in the request form?

Thank you,

Jul
24
3 months ago
Activity icon

Started a new Conversation Array Validation Rule And Old()

I am trying to make one field as an array of 2 fields

<div class="col-md-3">
    <label for="due_diligence_fee">Due Diligence Fee ($/%)</label>
    <div class="input-group">
        @dump(old('due_diligence_fee[fee]'))
        <input id="due_diligence_fee" name="due_diligence_fee.fee" type="text" class="form-control @error('due_diligence_fee.fee') is-invalid @enderror" value="{{ old('due_diligence_fee[fee]', $defaults->due_diligence_fee['fee']) }}">
        <div class="input-group-append">
            <select id="due_diligence_fee_symbol" name="due_diligence_fee.symbol" class="custom-select dropdown-toggle @error('due_diligence_fee.symbol') is-invalid @enderror">
                <option value="">($/%)</option>
                <option value="$" {{ old('due_diligence_fee.symbol', $defaults->due_diligence_fee['symbol']) === "$" ? 'selected' : '' }}>$</option>
                <option value="%" {{ old('due_diligence_fee.symbol', $defaults->due_diligence_fee['symbol']) === "%" ? 'selected' : '' }}>%</option>
            </select>
        </div>
        @error('due_diligence_fee.fee')
            <span class="invalid-feedback" role="alert">
                <strong>{{ $message }}</strong>
            </span>
        @enderror
    </div>
</div>

I am using a form request because I have many fields like that. My question:

  1. How do I make the validation rule:
return [
            'due_diligence_fee.fee'    => 'required|digits_between:0,100',

];
  1. how to catch the field as old in edit like:
value="{{ old('due_diligence_fee[fee]', $defaults->due_diligence_fee['fee']) }}"

For some reason, it's not working. Anyone could help me please :)

Jul
03
3 months ago
Activity icon

Started a new Conversation How Can I Get A 10 Digit Faker Random Number?

I am trying to get a $faker phone number but I need it to be 10 digits only. Is there a way to get 10 digits from faker?

Thank you,

Jun
28
3 months ago
Activity icon

Commented on Basic View Tweaks

You tweaked the test to make it work, but actually the pagination made the feature not working when you try to go to page 2 while you are in unanswered or popular threads.