themsaid

themsaid

Member Since 4 Years Ago

Cairo

Web Developer at Laravel

Experience Points 5,820
Experience Level 2

4,180 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 4
Lessons
Completed
Best Reply Awards 6
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

17 Dec
6 months ago

themsaid left a reply on Laravel Forge + Redis

@dmitry.g.ivanov just install it in your project even if you're only going to use it in production

themsaid left a reply on Trying To Send Email: Class SetQueue Does Not Exist

@unsoft did you manage to understand what was going on here? Also what was your php version?

14 Dec
6 months ago

themsaid left a reply on Envoyer Not Receiving Code

Can you please email envoyer at laravel.com with your project ID?

themsaid left a reply on Forge Disk Size Defaults To 20 GB .... How To Create Bigger?

Yes you'll need to do that from AWS.

themsaid left a reply on We Were Unable To Deploy Your Site Because Your Bitbucket Token Is Invalid For This Repository Or Has Expired.

Michael,

Are you the server owner? Forge uses the server owner's connected BitBucket account. If you're the owner then make sure your account does have access to this repo.

themsaid left a reply on Manage Multiple Servers

You can upgrade to the Growth plan to add more servers. The business plan is recommended if you want to share the servers with other developers.

themsaid left a reply on Laravel Forge + Redis

@DMITRY.G.IVANOV - You can either use the redis PHP extension or predis (https://github.com/nrk/predis) Laravel supports both, so Forge lets you decide what you want.

24 Sep
9 months ago

themsaid left a reply on I Did Not Get Sudo Password And Database Password On Creating A Server In Forge

Hey,

We've fixed that, it was a UI issue where the server creation forms are still visible even when the subscription is not active.

29 May
1 year ago

themsaid left a reply on Conditionally Pushing Event Listeners To Queue

In recent versions of laravel we added a new shouldQueue() method that if you define in your listener class and return true the listener will be queued, otherwise it won't.

So add a shouldQueue() method in your listener, return a boolean that decides if it gets queued or not.

02 May
1 year ago

themsaid left a reply on Having Issues Starting Nginx On Server Reboot

We believe that it's an issue with the latest nginx release, we've included "systemctl enable nginx.service" in your nginx installation scripts so we instruct nginx to autorestart after server reboot.

For servers created without this, you'll have to ssh to your server and run it.

16 Apr
1 year ago

themsaid left a reply on Forge Auto-updating Pip Packages?

For anyone wondering about this, the letsencrypt client required a pip upgrade so it can install the required dependencies to issue new certificate or renew existing ones.

So if any of your certificates were renewed or a new certificate was issues, pip was updated.

31 Oct
1 year ago

themsaid left a reply on How Do I Save Values From Multiple Select To An Array Or SQL DB

I'd just do:

return view('schedules.create')->with('doctors_names', 
    Doctor::pluck('name', 'id')
);  

Now the form input will have options where the label is the doctor name and the value as doctor id, now you have the ids of the selected doctors, if you want the names you can do pluck('name', 'name')

15 Aug
1 year ago

themsaid left a reply on Why Does UpdateOrCreate() Update All Records?

Can you use DB::enableQueryLog() before the call and dd(DB::getQueryLog()) after it so that it prints the queries that ran?

themsaid left a reply on Why Does UpdateOrCreate() Update All Records?

Well it should work as you expect, it'll try find records with the same entry_id and date, if some were found it'll update it. Are you sure it update entries with different dates?

themsaid started a new conversation What Is A Complex/nasty Queue Related Situation You've Ever Faced?

Hello everyone,

I've been collecting some ideas for Horizon's next set of features and would like to hear from you, what's a queue-related situation you've been into at work that drove you nuts?

Also feel free to suggest features you've seen in other queue systems.

10 Feb
2 years ago

themsaid left a reply on How To Register/Create A User Programmatically?

Hello there,

It depends on your user case really, like if you simply want to create a new Spark user that's on a generic trial you can simply use Eloquent's create() method as you'd do with any Model, that's actually how spark does it:

    $user = Spark::user();

    $user->forceFill([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
        'last_read_announcements_at' => Carbon::now(),
        'trial_ends_at' => Carbon::now()->addDays(Spark::trialDays()),
    ])->save();

    return $user;
01 Dec
2 years ago

themsaid left a reply on How To Paginate The Array?

Please share the error stack.

04 Nov
2 years ago

themsaid left a reply on Array Validation Does Not Work If They Are Files

That was a bug during files hydration by the validator, it's now fixed by entirely removing the hydration process and interact with both files and other input in the same manner.

03 Nov
2 years ago

themsaid left a reply on Array Validation Does Not Work If They Are Files

Hello everyone :)

Would like to help with the issue but I can't replicate, can you please share the exact laravel version along with the actual input, because I see you're validating size but the output you shared doesn't include any:

array:4 [
  "_token" => "QJGTR3Y9kNV13IpF2sucA3YiJBSuSVVyB3C9fAwT"
  "_method" => "POST"
  "title" => "something"
  "color" => array:1 [
    0 => UploadedFile {#294 }
  ]
]

Can you also share the validation error you receive?

21 Sep
2 years ago

themsaid left a reply on Laravel 5.3 Validation Of Multiple Images ?

You can use $errors->has('image.*')

themsaid left a reply on Laravel 5.3 Validation Of Multiple Images ?

Yeah that's a bug, fixing atm.

themsaid left a reply on Laravel 5.3 Validation Of Multiple Images ?

Can you please share the validation error messages you currently receive?

themsaid left a reply on $fillable And Create() Not Working

What's the purpose of

return Setting::firstOrNew($input);

themsaid left a reply on Laravel 5.3 Validation Of Multiple Images ?

You'll need to supply names for the name.* format:

'attributes' => [
    'image.1' => 'фотографии',
],

themsaid left a reply on Laravel 5.3 Validation Of Multiple Images ?

How would you like to change it?

themsaid left a reply on Laravel 5.3 Validation Of Multiple Images ?

Please upgrade to 5.3.10, this issue was fixed.

themsaid left a reply on Calling To Member Function On Boolean

The Model::save() method returns a bool, you need to use an instance of the model as @InaniELHoussain mentioned.

themsaid left a reply on Laravel 5.3 Passport Unsupported Grant_type

Please provide full request payload.

themsaid left a reply on Manually Approving A User After They Register

I'd use a flag is_approved that is false by default for newly created users, add a check to make sure the user trying to log in is approved, and create an admin screen to approve/disapprove users.

themsaid left a reply on How To Validate Date With Only Year Input

@jake2025 I'd simply go for this if the input value is a year.

'pricing_date' => 'required|min:1900|max:'.date("Y"),

If the input value is a full date and you only want to validate the year check @InaniELHoussain's answer.

themsaid left a reply on Laravel 5.3 Validation Of Multiple Images ?

You mean when the field is empty, no images to upload?

Please mention your full laravel version (5.3.#).

06 Feb
4 years ago

themsaid left a reply on Separate Users Table, (application_users & Backend_users)

Why not have a single model, single table and use a factory to load different classes based on the user type?

21 Jan
4 years ago

themsaid started a new conversation How Big An Aggregate Can Be?

If you think of it, it's most common that the User entity will be a big fat aggregate with a bunch of methods: addComment, updateComment, deleteComment, followUser, createTicket, etc...

The question is how big an aggregate should be? is there a role for when to split an aggregate and delegate the responsibility of performing some actions to another aggregate?

themsaid left a reply on Create A Eloquent Relationship Between A Parent Table And A Lookup Table?

Hey, The relation should be as follow

class Mission extends Eloquent {
    public function launchSite() {
        return $this->belongsTo('LaunchSite', 'launch_site_id');
    }
}

class LaunchSite extends Eloquent {
    protected $table = 'launch_sites';

    public function mission() {
        return $this->hasMany(launch_site_id');
    }
}

Now the Mission belongs to only one LaunchSite, and a LaunchSite has many missions.

20 Jan
4 years ago

themsaid left a reply on How To Deal With Relationships On Entities Without Extending Eloquent?

A very good idea. I'm using ELoquent to benefit from some features like eager loading, synchronising many-to-many relationships, etc...

themsaid left a reply on How To Deal With Relationships On Entities Without Extending Eloquent?

Even with the query builder, if for example I have 3 comments already in User->comments, and I used addComment to add another one, on saving the $user I'll see 4 comments in the comments property, 3 already in the DB and 1 in memory, how can I distinguish between them to save only the newly created one?

themsaid started a new conversation How To Deal With Relationships On Entities Without Extending Eloquent?

Let's say I have a POPO User class, I'm using a repository to create/update/delete the ELoquentUser entities, I also use a mapper class that converts Eloquent to POPO and POPO to ELoquent.

My question is, how can I deal with relationships?

For example:

class User{
    public $name;
    public $comments = [];

    function ... // constructor here

    function addComment(Comment $comment){
        $this->comments[] = $comment;
    }
}

Now in the repository upon saving, I'll have to do something like:

$user = ELoquentUser::fill(['name'=> $name]);
$user->save();

// saving the new comment here

So how can I save the newly created/edited comments, so that when I execute $user->addComment(new Comment('comment text')); and then '$userRepository->save($user)' saves the new coment?

15 Jan
4 years ago

themsaid left a reply on Using Doctrine Vs. Creating POPO Entities Out Of Eloquent Models

Just had this reply from someone on larachat

ddd = doctrine doctrine doctrine

that's funny :D

themsaid left a reply on Using Doctrine Vs. Creating POPO Entities Out Of Eloquent Models

And how about using the query builder to retrieve data, and then convert them to POPOs?

themsaid left a reply on Check If User Fill Their Username Or Not

I'd thing of creating a middleware to check if the user has a username, and if so I'l display a nice page asking him to fill the username to continue.

themsaid started a new conversation Using Doctrine Vs. Creating POPO Entities Out Of Eloquent Models

I've been doing some research on DDD, and I find most of the talk is headed towards doctrine, however I really love the fluent syntax of Laravel's Eloquent and don't want to abandon it, so I was thinking of creating entities as POPOs and have the repository handle the task of converting POPOs to Eloquent models and save them, and to convert Eloquent models to POPOs on retrieval and present them.

The question is, is that a good approach in terms of good architecture and performance? If not, are there any other approaches on how to implement DDD and use Eloquent at the same time?

14 Jan
4 years ago

themsaid left a reply on Users And Roles

There are many other ways to do this, however I find this more straight forward. Here's a tricky situation:

what if you want to give the user and admin role BUT remove his ability to delete_post?

To do that, you can add a column in the user_capability pivot table, let's say:

user_capability
--- user_id
--- capability_id
--- has

The has flag can be 0, or 1 with 0 indicating that this capability should be excluded, 1 one means this capability should be added.

So the can method can be something like:

function can($capability)
{
   $can = false;

    // if the capability exists in the users's role capabilities
    if( in_array($capability, $this->role->capabilities->lists('key')) )
    {
        $can  = true;
    }

    if( in_array($capability, $this->capabilities->wherePivot('has', 0)->lists('key')) )
    {
        $can  = false;
    }

    // If the capability is assigned specially for this user
    if( in_array($capability, $this->capabilities->wherePivot('has', 1)->lists('key')) )
    {
        $can  = false;
    }

    return $can;
}

Of course this code can be optimized, however I'm just showing how things can be like.

themsaid left a reply on Error Testdummy

I also face the same problem when I add a column in the model's $dates property

themsaid left a reply on Users And Roles

I'd consider having a structure like this:

User
--- user name
--- role_id

Role
--- role name

Capability
-- name
-- key

role_capability
--- role_id
--- capability_id

user_capability
--- user_id
--- capability_id

So to check if the user can do "delete_post", you might do

// User model

function can($capability)
{
    if( in_array(capability, $this->role->capabilities->lists('key')) )
    {
        return true;
    }

    if( in_array(capability, $this->capabilities->lists('key')) )
    {
        return true;
    }

    return false;
}

themsaid left a reply on L5 Structure And Default Files Confusing

Since not everything isn't documented yet, you'll need to dig in the framework source and try playing around yourself. Not sure if removing this class will break the framework? remove it, got broken? debug and you'll know why it's there.

18 Dec
4 years ago

themsaid left a reply on L4 Or L5 For New Project?

I believe L5 can only be used for experimenting the new features, however for an application development L4 should be used.