Support the ongoing development of →
Input Eloquent Database
Last updated 1 year ago.

Hi Ghost,

There is a Lot of things that you should do such create a validation method on you controller,

add a scope to Member:

public function scopeEmails($query, $email)
   return $query->where('email', $email)->first()->exists();

Then you can say:


and it will return true or false, you do not need to check mobile, just set the email to unique and will blow up in the create method.

            return App\Member::create($array);
        catch (QueryException $e)
            $error_code = $e->errorInfo[1];
            if ($error_code == 1062)
                /* try an email that belongs to a member */
                return false;

I hope that shines a light

Last updated 5 years ago.

@lukmauu That didn't work, Let me explain again, what i want to do. I want to check if a member with a particular email exists before creating the member.

so what i want is. In a family i want the members to have a unique email. That's prevent another member from been added to the family with email. thanks.



In Family you must have:

public function members()
    return $this->hasMany(Member::class);

=> and in Member you must have:

public function family()
    return $this->belongsTo(Family::class, 'family_id');

public function scopeEmail($query, $email)
    return $query->Where('email', $email)->count() > 0;

=> and now you can say:

App\Family::findOrFail(10)->members()->email('[email protected]')

=>It will return a bool true if the some member of this Family exists with this email or false otherwise.

=>and also there is a difference between:



Last updated 4 years ago.

@lukmauu didn't later use your method, i did this

 $member_email  =  Member::where("family_id", "=", $request->family_id)->where('email', "=", Input::get('email'))->first();
        $member_mobile  =  Member::where("family_id", "=", $request->family_id)->where('mobile', "=", Input::get('mobile'))->first();

Then i used it

 if($member_email OR $member_mobile ){
//enter code here

Thanks for the help.


Sign in to participate in this thread!


Your banner here too?

Ghost ghostly Joined 19 Apr 2019


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.