Welcome, Guest: Join Nairaland / LOGIN! / Trending / Recent / New
Stats: 2,864,212 members, 6,872,594 topics. Date: Friday, 20 May 2022 at 05:48 PM

[Code Review Help] Laravel Experts Please HELP! - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / [Code Review Help] Laravel Experts Please HELP! (1690 Views)

How To Echo The Rank/position Of A Student. Codeigniter Experts, Please Help / [Code Review Help] Explanation In Java Needed / Wordpress Experts, Please Help A Brother! (2) (3) (4)

(1) (Reply) (Go Down)

[Code Review Help] Laravel Experts Please HELP! by davinchecodes(m): 7:35pm On Apr 19, 2019
Am new to laravel (total greenhorn), it would be awesome if anyone can help me with this.

Checking if data exists in child of a parent before creating new child.

I have a model called Family and another called Member. My relationship looks like below.

class Family extends Model
{
public function member()
{
return $this->hasMany('App\Member');
}
}
And members

class Member extends Model
{
public function family()
{
return $this->belongsTo('App\Family');
}
}
I would like to check if in the current family if a member with the email from the input form exists or not. If exists returns error (a member with that email already existed in this family) else Creates the new member in that family. How would you suggest i do this?

what i have done but it's wrong though.

$member_mobile = Member::with('families')->where('mobile', '=', Input::get('mobile'))->first();
if(!$member_email || !$member_mobile){
$member = new Member();
$member->firstname = $request->firstname;
$member->lastname = $request->lastname;
$member->email = $request->email;
$member->mobile = $request->mobile;
$member->fid = $request->fid;
$member->family_id = $request->family_id;
$member->gender = $request->gender;
$member->role_id = $request->role_id;
$member->avatar = $avatar;
$member->save();
}

else{
return redirect()->back()->with('Error','Oops! Member email or mobile number exists already');
}




How do you think i should go about it cry.

@codeblooded
Re: [Code Review Help] Laravel Experts Please HELP! by Echatbook: 8:24pm On Apr 20, 2019
what you are trying to do is not clear
Re: [Code Review Help] Laravel Experts Please HELP! by FincoApps(m): 12:53am On Apr 21, 2019
Do something like this:

$family = Family::find($family_id);

$member_mobile = $family->member->where('mobile', '=', Input::get('mobile'))->first();

if($member.....){}
else{...}
Re: [Code Review Help] Laravel Experts Please HELP! by abula112(m): 6:54am On Apr 22, 2019
Altechtic MFB microfinance web app built with laravel, bootstrap and vue.js.

features:
* Customer with more than one wallet.
*Admin and staff with same permission, but admin can create and delete staff.
*Withdraw to other banks with dynamic fee
*Transfer to other wallet
*All transactions by customer secured by verification pin
*Admin can suspend or activate customer
*Admin can edit customer profile
*Loan application and loan payment
*Realtime transactions history on Admin dashboard for specific timeframe
*Sms notification
*Bill payments(dstv, nepa, etc).
And more....

Picture will be uploaded soon... contact 08106813749 for a demo and pricing.
Re: [Code Review Help] Laravel Experts Please HELP! by davinchecodes(m): 3:21pm On Apr 23, 2019
FincoApps:
Do something like this:

$family = Family::find($family_id);

$member_mobile = $family->member->where('mobile', '=', Input::get('mobile'))->first();

if($member.....){}
else{...}

Thanks for your help bro/sis, I have been able t solve it.
i did mind this way though
[quote]
$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();

if($member_email){.....}
else{...}

wink
Re: [Code Review Help] Laravel Experts Please HELP! by DOBOEFEMENA: 12:52pm On Aug 22, 2019
davinchecodes:
Am new to laravel (total greenhorn), it would be awesome if anyone can help me with this.

Checking if data exists in child of a parent before creating new child.

I have a model called Family and another called Member. My relationship looks like below.

class Family extends Model
{
public function member()
{
return $this->hasMany('App\Member');
}
}
And members

class Member extends Model
{
public function family()
{
return $this->belongsTo('App\Family');
}
}
I would like to check if in the current family if a member with the email from the input form exists or not. If exists returns error (a member with that email already existed in this family) else Creates the new member in that family. How would you suggest i do this?

what i have done but it's wrong though.

$member_mobile = Member::with('families')->where('mobile', '=', Input::get('mobile'))->first();
if(!$member_email || !$member_mobile){
$member = new Member();
$member->firstname = $request->firstname;
$member->lastname = $request->lastname;
$member->email = $request->email;
$member->mobile = $request->mobile;
$member->fid = $request->fid;
$member->family_id = $request->family_id;
$member->gender = $request->gender;
$member->role_id = $request->role_id;
$member->avatar = $avatar;
$member->save();
}

else{
return redirect()->back()->with('Error','Oops! Member email or mobile number exists already');
}




How do you think i should go about it cry.

@codeblooded
nice , kindly provide me your email address . Thanks.
Re: [Code Review Help] Laravel Experts Please HELP! by davinchecodes(m): 3:36pm On Aug 22, 2019
DOBOEFEMENA:
nice , kindly provide me your email address . Thanks.
I have sent you a dm.
pls don't quote this email in your reply..
I don't want email harvester to scrap it
Re: [Code Review Help] Laravel Experts Please HELP! by samueltoski: 9:24pm On Aug 25, 2019
Use if(isset($member)){}
Re: [Code Review Help] Laravel Experts Please HELP! by davinchecodes(m): 8:48am On Aug 26, 2019
samueltoski:
Use if(isset($member)){}
Thanks, i already switched it to using isset()
Re: [Code Review Help] Laravel Experts Please HELP! by ndukweoge(f): 5:40pm On Oct 09, 2019
trying to implement paystack transfer/withdrawal api on my laravel project, not sure how. Any help will be appreciated
Re: [Code Review Help] Laravel Experts Please HELP! by MrCodeSolo: 1:16am On Oct 10, 2019
Omo! see boilerplate codings for (Php Laravel)...let me just stick to my procedural way of coding with core Php.. maybe in the future I go switch to the former.

1 Like

Re: [Code Review Help] Laravel Experts Please HELP! by MrCodeSolo: 1:30am On Oct 10, 2019
ndukweoge:
trying to implement paystack transfer/withdrawal api on my laravel project, not sure how. Any help will be appreciated
look into paystack documentation with PHP Laravel socket...on their official site under developers' section
Re: [Code Review Help] Laravel Experts Please HELP! by talk2hb1(m): 9:58am On Oct 11, 2019
MrCodeSolo:
look into paystack documentation with PHP Laravel socket...on their official site under developers' section
What Socket?

(1) (Reply)

What Is Pushing You Back In Web Development? / Favorite Sections On User Profiles / Aptech Or New Horizon

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2022 Oluwaseun Osewa. All rights reserved. See How To Advertise. 90
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.