EslamAhmed

EslamAhmed

Member Since 5 Months Ago

Experience Points
5,560
Total
Experience

4,440 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
15
Lessons
Completed
Best Reply Awards
7
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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 2
5,560 XP
Aug
11
5 months ago
Activity icon

Replied to Validate Multiple Select / Not_in Rule

You can use the arrays validation, check the documentation here https://laravel.com/docs/5.8/validation#validating-arrays

So, based on the rules you want to apply, your code should look like this

[
    'exlcudedShips.*' => 'integer|not_in:shipsTo|exists:countries,id'
]
Activity icon

Replied to How To Search Code In Laravel

Well, as @aurawindsurfing said, it's better to do it as a post route not a get route.

To fix the issue in your screenshot, first fix your route to be

Route::post('/document', '[email protected]')->name('document');

Your controller function will be

public function document(Request $request)
{
    $keyword = $request->input('code');
    $documents = Document::document($keyword)->latest()->get();
    return view('Home.content.documents', compact('documents'));
}
Activity icon

Replied to How To Get Date Difference For Date Column Against Current Date In Laravel ?

A little bit of basic mathematics, so you can understand the idea of comparison you want to do:

If the desired result is schedule - current_date <= 30 and also schedule - current_date => 1

hence current_date < schedule <= current_date + 30

So the final code will be

$maxDate = Carbon::now()->addDays(30)->toDateTimeString();
$minDate = Carbon::now()->toDateTimeString();
$current = Amortization::select('loan_type', \DB::raw('SUM(loan_amortization) as total_current'))
                                ->where('payment_status',0)
                                ->whereDate('schedue', '<=', $maxDate) // Difference is equal or less than 30
                                ->whereDate('schedue', '>', $minDate) // Difference is greater than 1
                                ->groupBy('loan_type')
                                ->orderBy('loan_type')
                                ->get();
Aug
10
5 months ago
Activity icon

Replied to How To Get Date Difference For Date Column Against Current Date In Laravel ?

You can use carbon to format any date as you like https://carbon.nesbot.com/docs/

//To add 30 days from now and get the date formatted
$date = Carbon::now()->addDays(30)->toDateTimeString();

//To subtract 30 days from now and get the date formatted
$date = Carbon::now()->subDays(30)->toDateTimeString();

Then you can use this date in your query condition

$current = Amortization::select('loan_type', \DB::raw('SUM(loan_amortization) as total_current'))
                                ->where('payment_status',0)
                                ->where('schedue', '<=', $date)
                                ->groupBy('loan_type')
                                ->orderBy('loan_type')
                                ->get();
Activity icon

Replied to Remap Id As ID

Yeah, it was a typo mistake, I've fixed it. Did it work for you?

You can change the column name of an existing database though. https://laravel.com/docs/5.8/migrations#columns

But if the previous solution works for you then it's all good.

Activity icon

Replied to How To Properly Install Package?

You can follow this guide to install TinyMCE editor to your application, there are multiple options there, choose whatever you like

https://www.tiny.cloud/docs/general-configuration-guide/advanced-install/

Activity icon

Replied to Remap Id As ID

Well, you don't actually need to rename the column for that. But I recommend using the lower case naming for database columns.

If you want to use "ID" as your primary key, just add this line in your model

protected $primaryKey = "ID";
Aug
09
5 months ago
Activity icon

Replied to How To Get Data From URL Using PHP

If the data you want to parse is XML, then you don't need to use regular expressions to extract something from it.

Just use an XML parser, if $vehicleXml is the variable that holds the XML data, this might work for you

$vehicle = new SimpleXMLElement($vehicleXml);
$permo = $vehicle->permno;
$make = $vehicle->make;
$vehcom= $vehicle->vehcom;
Activity icon

Replied to Favourite / Un-Favourite Button

If you want to toggle the button without refreshing the page, you will have to do that in your ajax success function.

So if it was a favorite button, after clicking it, it will change entirely to the un-favorite button

There are multiple ways to replace the buttons with each other, you can take a look at replaceWith for example https://api.jquery.com/replaceWith/

Activity icon

Replied to Implementing API Email Verification

Well, it's up to you if you want to verify the email and log the user into the system or just verify the email and let him login by himself. But I prefer to let the user login by himself after the verification.

To redirect the user, just use the redirect method https://laravel.com/docs/5.8/redirects#creating-redirects

return redirect()->route('login');

______

If you have the URL not found issue, maybe you have a fresh apache installation? if yes you need to run these commands and try again

sudo a2enmod rewrite
sudo service apache2 restart
Activity icon

Replied to One To Many Pivot Table To Save Extra

Ok then, in that case, it's better to add a new table like you did to hold the coupon_id, the subscription_id and the count_usage of that coupon.

Then compare that count_usage with the maximum usage allowed for the coupon.

Activity icon

Replied to Route Issue

It says that it can't find a route named upload.edit_property_form, maybe you are calling this route with that name somewhere in your code, so if you want this route to take that name, it should look like this

Route::get('/edit_property_form','[email protected]_form')->name('upload.edit_property_form')

https://laravel.com/docs/5.8/routing#named-routes

Activity icon

Replied to One To Many Pivot Table To Save Extra

There are two solutions based on what do you need to do and what do you need to have on your database:

1- If you would like to save only a count of how many times this coupon is used as just a number in the database, then i don't think you will need a new table for "coupon_usages", because as I understood from you that the coupon is already related to a subscriptions (means that the subscription_id is already in the coupons table). So, in this case, you can add the "usage_count" column in the coupons table and update it regularly then compare it with another column in the same table "max_usage" to determine if it exceeds the usage limits or not.

2- If you would like to keep track with which user used which coupon for more detailed tracking, in this case as I told you, you will need a new table "coupon_user" that will save the coupon_id and the user_id.

________

In both cases, you will need to have a "max_usages" column in the coupon's data, and in both cases, you can also save the "usage_count" in the coupons table as well. But in the second option, you can do the usage count dynamically by counting the records related to that coupons.

Activity icon

Replied to Many-to-Many Limit Has() By Pivot Attribute

You are welcome :)

Good luck!

Aug
08
5 months ago
Activity icon

Replied to How Do I Attach A File To A Notification Email?

Yes, the function that you should use is attach, and it should look like this

public function toMail($notifiable)
{
        return (new MailMessage)
               ->line('Hello there')
               ->attach(storage_path() . "/app/library/code-conduct-2014.pdf");
}
Activity icon

Replied to One To Many Pivot Table To Save Extra

Maybe you can create a new table "coupon_user" that will save the coupon_id and the user_id, so now you can keep track of the coupon usage and which users applied it.

If you want to make a maximum allowed number of usages for that coupon, you can add a new integer column for it in the coupons table.

Then it's easy to query the database to know if a specific coupon reached its maximum usage or not

Activity icon

Replied to Loop Through An Array Of Multiple Values

If $category is an array of values that you want to filter with, You can use the whereIn function

$Tagids = DB::table('tags')
                    ->whereIn('t_name', $category)                  
                    ->pluck('id'); 
Activity icon

Replied to Delete Notification

Can you give more details so we can help?

Like what kind of notifications and how is it stored and how do you want it to be deleted?

Activity icon

Replied to ReflectionException (-1) Class Post Does Not Exist

Did you try to clear the config cache?

Try to run

composer dump-autoload

Then

php artisan config:clear
Activity icon

Replied to Conditional Redirect After Registration

If you are asking where to put the redirection logic, there is a function that fires immediately after the user is registered successfully. It's in the RegistersUsers trait but you can override it in the RegisterController

Just copy and paste it in the RegisterController

protected function registered(Request $request, $user)
    {
        //
    }

You can use the $request and the $user that is already created to determine the logic happens after that and put your redirection logic in that function.

For redirects, you can check the documentation here: https://laravel.com/docs/5.8/redirects

Aug
07
5 months ago
Activity icon

Replied to Getting Distinct Rows From A Model With Relationships

If you are selecting the popular brands based on the products sale, maybe you could add the count of all the products sale together for each brand then list those brand based on that final sale count.

This is an example for using count and groupBy

https://laravel.com/docs/5.8/queries#raw-expressions

You can share the code of brands listing query if this doesn't work with you so we can help better :)

Activity icon

Replied to Many-to-Many Limit Has() By Pivot Attribute

You are welcome :)

Yes it can be done using the eager loading with a closure, and the final query will look like that

$dances = Dance::whereHas('callers', function (Builder $query) {
    //Put your conditions here
    $query->where("date_of", '>', ....);
})->with(['callers' => function ($query) {
    $query->where('date_of', '>', ....);
}])->get();

The whereHas closure condition will limit the "dance" records and will get only those that is related to any "caller" record with "date_of" in the desired date.

The with closure condition will limit the "callers" returned from the eager loading for that "dance" record with "date_of" in the desired date.

Activity icon

Replied to Many-to-Many Limit Has() By Pivot Attribute

You can use the whereHas method instead of has

https://laravel.com/docs/5.8/eloquent-relationships#querying-relations

$dances = Dance::whereHas('callers', function (Builder $query) {
    //Put your conditions here
    $query->where("date_of", '>', ....);
})->with('callers');
Activity icon

Replied to Don't Create Field In Database

Yes, it was a typo in my code, I've fixed it.

Try it again

Activity icon

Replied to Relation Between Same Users Table

I think it's better if you isolate this extra data because it's a data related only to runners user roles, so you should create a new table 'runners' and this table will have:

user_id: the user id of the runner

coach_id: the user id of the coach

In that situation, there will be a Runner model that will have a one-to-many relationship with the users table through the "coach_id" column

And if the coaches have more and different data than the runners (for example years of experience or his gym's address) then you should create a new table for coaches as well. Then the models and relations will change based on that.

Check the documentation here for more info about relations and how to do it in laravel models https://laravel.com/docs/5.8/eloquent-relationships

________________

Generally, if a specific user role has some data that the other roles don't have it, you shouldn't put it in the users table

Activity icon

Replied to Don't Create Field In Database

You will have to check if there is a value in $request['repair_report_buro'] before going to the database creation

if the $request is an instance of Illuminate\Http\Request

if($request->filled('repair_report_buro')){
   $delivery->comments_buro()->create([
        'name' => auth()->user()->firstname,
        'user_id' => auth()->user()->id,
        'message' => $request['repair_report_buro'],
        'icon' => 'fa fa-commenting-o',
        'style' => $position->style,
    ]);
}
Activity icon

Replied to Queue Process Implementation In Lumen

Jobs functionality in laravel and lumen is almost the same, the big difference is the way of creating a new job.

To create a job in laravel php artisan make:job TestJob

To create a job in lumen you will have to copy the ExampleJob file in jobs folder and use it as much as you want.

https://lumen.laravel.com/docs/5.8/queues

https://laravel.com/docs/5.8/queues

Activity icon

Replied to Validation Rule “between” For Array Of Checkboxes Always Valid

I think the problem is that the form returns an array and your code is trying to validate it as a variable, check the documentation here on how to validate an array of inputs https://laravel.com/docs/5.8/validation#validating-arrays

In your case:

$validationRules = [
    '11.*' => 'between:0,2',
];
Aug
06
5 months ago
Activity icon

Replied to Advice Regarding Scheduled Tasks

In your situation, I don't think there will be any difference between the two approaches regarding the functionality and the result. Also, they are both are going to be running in the background.

For me, I would use a command if I need to run the script manually through the command line for any reason (for example in your case, to run the script for a specific user and send him an email), or for a one-time functionality script that runs on demand (like database migrations or clearing cache or deleting logs).

Activity icon

Replied to Can't Download File

You can do something like that:

web.php

Route::get('team-form/{user}/{file}', '[email protected]')->name('clientDownload');

TeamFormController

public function downloadClientFile($user, $file) {
        return response()->download(storage_path('app/upload/client/' . $user . '/' . $file));
    }

view

<a href="{{ route('clientDownload', ['user' => $teamform->forms->users->name, 'file' => $teamform->forms->upload]) }}">Download</a>
Activity icon

Replied to Can't Download File

Hi,

I suggest you create a new route for downloading those files from the storage and use this method from laravel documentation https://laravel.com/docs/5.8/filesystem#downloading-files

or it could be something like that

return response()->download(storage_path("app/upload/client/....."));

Make sure to secure this route if these files are restricted to a specific user role.

_______________

Another way if you want to make those files accessible from public you can follow the documentation by using

php artisan storage:link

here https://laravel.com/docs/5.8/filesystem#configuration

But I really prefer the first approach