Cyber Monday! Get 25% off for as long as you keep your subscription. New subscribers only.

rafidAhsan

rafidAhsan

Member Since 5 Months Ago

Experience Points
13,840
Total
Experience

1,160 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
114
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 3
13,840 XP
Nov
28
3 days ago
Activity icon

Replied to Dynamic Css Background-image

@snapey Thank you so much

Activity icon

Replied to Dynamic Css Background-image

 style="background-image: url('{{ asset('/img/{{ $property->property_image }}') }}')"
Activity icon

Started a new Conversation Dynamic Css Background-image

What is the right syntax to write this

style="background-image: url('{{ asset('{{ $property->property_image }}') }}')">
Nov
17
2 weeks ago
Activity icon

Replied to Multiple Corn Jobs Command Are Not Getting Executed.

@snapey Then you don't have any business critical logic in the server configuration - it can live in your application in version control.

Can you elaborate pleas.

Thank you

Activity icon

Replied to Multiple Corn Jobs Command Are Not Getting Executed.

@sinnbeck When I try to execute individual command in my localhost they do work. But unfortunately the same command is not executed in cPanel. Even after when I use schedule:run command. So therefore I was looking for some suggestions and assistants.

Thank you

Nov
16
2 weeks ago
Activity icon

Replied to Multiple Corn Jobs Command Are Not Getting Executed.

Can you give me any example. Do you mean to say that, I have to run both the commands at the same time? If the both command have to be executed then I have to ensure that individual commands work properly.

Thank you

Nov
15
2 weeks ago
Activity icon

Started a new Conversation Multiple Corn Jobs Command Are Not Getting Executed.

i have created the cron job for service charge, it works properly the purpose of service charge is to deduct a certain amount of money from every user after 10 months the same way i implemented cron job for default charge, and its purpose is to deduct a certain amount when user does not pay installment accordingly. Now the cron job for default does not get executed when i use it in cpanel. Hope someone can help me out

Service charge is working

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\SavingAcount;

use App\UserNotification;

use App\User;

use DB;

use App\Accounts;

use App\ServiceChrg;

class ServiceCharge extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'day:juneFirst';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Your Service Charge is automatically cut from your savings by our system. Thanks for stay with us';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $users = User::get();

        foreach($users as $user) {
            $total = 0;
            if($user->hasSavings() == $user->id) {
                $service_charges = new ServiceChrg();
                $saving = SavingAcount::where('user_id', $user->id)
                    ->latest()
                    ->first();
                $saving->total = $saving->total - 20;
                $saving->save();

                $service_charges->user_id = $user->id;
                $service_charges->save();

                $total += 20;

                // Service charge goes to accounts
                $accounts = new Accounts();
                $accounts->service_charge = 20;
                $accounts->user_id = $user->id;

                $row = count(Accounts::select('service_charge')->where('user_id', $user->id)->get());
                if($row == 0) {
                    $accounts->total_service_charge = 20;
                    $accounts->total = 20;
                }   else {
                    $prev_fees = Accounts::where('user_id', $user->id)->latest()->first();
                    $accounts->total_service_charge = 20 + $prev_amount->total_service_charge;
                    $accounts->total = $accounts->total_service_charge + $accounts->total_default_charge + $accounts->total_fee;
                }

                $accounts->save();

                $username = "Alauddin101";
                $hash = "4f9ec55ab0531a44a466910119d97847";
                $numbers = $user->mobile_number; //Recipient Phone Number multiple number must be separated by comma
                $message = '20tk has been deducted for your service charge. Thank you! Your current saving is '.$saving->total;

                $params = array('app'=>'ws', 'u'=>$username, 'h'=>$hash, 'op'=>'pv', 'unicode'=>'1','to'=>$numbers, 'msg'=>$message);

                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, "http://alphasms.biz/index.php?".http_build_query($params, "", "&"));
                curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

                $response = curl_exec($ch);
                curl_close ($ch);

                $accounts->save();
            }
        }
    }
}

For Cpanel

/usr/local/bin/php /home/afreensh/bdloans.afreenshop.com/system/artisan day:juneFirst >> /dev/null 2>&1

Default Charge Command is not working. But I use same way

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\User;

use App\BusinessLoan;
use App\EduLoan;
use App\EmployeeLoan;

use App\SavingAcount;

use App\LoanInstallment;

class DefaultCharge extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'day:everyMonth';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Status of ddefault charge';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $users = User::get();

        foreach ($users as $user) {
            $user_id = $user->id;

            if($user->hasBusinessLoans() == $user_id) {
                $loan = BusinessLoan::where('user_id', $user->id)->where('completed', 0)->first();
                $loan_installments = LoanInstallment::where('loan_id', $loan->id)->latest()->first();

                if($loan_installments == '') {
                    // user doesn't give first installment
                    $saving = SavingAcount::where('user_id', $user->id)->latest()->first();
                    $saving->total = $saving->total - 20;
                    $saving->save();

                    // Default charge goes to accounts
                    $accounts = new Accounts();
                    $accounts->default_charge = 20;
                    $accounts->user_id = $user->id;

                    $row = count(Accounts::select('default_charge')->where('user_id', $user->id)->get());
                    if($row == 0) {
                        $accounts->total_default_charge = 20;
                        $accounts->total = 20;
                    }   else {
                        $prev_fees = Accounts::where('user_id', $user->id)->latest()->first();
                        $accounts->total_default_charge = 20 + $prev_amount->total_default_charge;
                        $accounts->total = $accounts->total_service_charge + $accounts->total_default_charge + $accounts->total_fee;
                    }

                    $accounts->save();

                    $username = "Alauddin101";
                    $hash = "4f9ec55ab0531a44a466910119d97847";
                    $numbers = $user->mobile_number; //Recipient Phone Number multiple number must be separated by comma
                    $message = '20tk has been deducted for your late of Loan from saving. Thank you! Your current saving is '.$saving->total;

                    $params = array('app'=>'ws', 'u'=>$username, 'h'=>$hash, 'op'=>'pv', 'unicode'=>'1','to'=>$numbers, 'msg'=>$message);

                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL, "http://alphasms.biz/index.php?".http_build_query($params, "", "&"));
                    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

                    $response = curl_exec($ch);
                    curl_close ($ch);
                }   else {
                    $to = \Carbon\Carbon::parse($loan->approved_date)->floorMonth();
                    $from = \Carbon\Carbon::parse($loan_installments->this_month)->floorMonth();
                    $net_installment_month = $to->diffInMonths($from);

                    if($loan_installments->amount < $net_installment_month * $loan->perInstallmentAmount) {
                        $saving = SavingAcount::where('user_id', $user->id)->latest()->first();
                        $saving->total = $saving->total - 20;
                        $saving->save();

                        // Default charge goes to accounts
                        $accounts = new Accounts();
                        $accounts->default_charge = 20;
                        $accounts->user_id = $user->id;

                        $row = count(Accounts::select('default_charge')->where('user_id', $user->id)->get());
                        if($row == 0) {
                            $accounts->total_default_charge = 20;
                            $accounts->total = 20;
                        }   else {
                            $prev_fees = Accounts::where('user_id', $user->id)->latest()->first();
                            $accounts->total_default_charge = 20 + $prev_amount->total_default_charge;
                            $accounts->total = $accounts->total_service_charge + $accounts->total_default_charge + $accounts->total_fee;
                        }

                        $accounts->save();

                        $username = "Alauddin101";
                        $hash = "4f9ec55ab0531a44a466910119d97847";
                        $numbers = $user->mobile_number; //Recipient Phone Number multiple number must be separated by comma
                        $message = '20tk has been deducted for less amount then per installment amount of Loan from saving. Thank you! Your current saving is '.$saving->total;

                        $params = array('app'=>'ws', 'u'=>$username, 'h'=>$hash, 'op'=>'pv', 'unicode'=>'1','to'=>$numbers, 'msg'=>$message);

                        $ch = curl_init();
                        curl_setopt($ch, CURLOPT_URL, "http://alphasms.biz/index.php?".http_build_query($params, "", "&"));
                        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
                        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

                        $response = curl_exec($ch);
                        curl_close ($ch);

                        return 0;
                    }   else {
                        return 0;
                    }
                }
            }   elseif($user->hasEmployeeLoans() == $user_id) {

            }   elseif($user->hasEduLoans() == $user_id) {

            }   else {
                // user has no loan
                return 0;
            }
        }
    }
}

Cpanel code for default charge

/usr/local/bin/php /home/afreensh/bdloans.afreenshop.com/system/artisan day:everyMonth >> /dev/null 2>&1
Nov
10
3 weeks ago
Activity icon

Started a new Conversation Best Way To Design As Accounts Table

I want to know the best way to design an accounts table where just 3 differents of data are stored but not at the same time. The main columns are

Service Charge Default Charge Loan fee

Oct
30
1 month ago
Activity icon

Replied to Call To A Member Function (businessLoans()) On Int

Shit. Lol!! Anyways thank you. I missed that part

Activity icon

Started a new Conversation Call To A Member Function (businessLoans()) On Int

I don't figure out the problem.

$users = User::get();

        foreach ($users as $user => $value) {
            if($user->hasBusinessLoans() == $user_id) {
                $loan = BusinessLoan::where('user->id', $user->id)->where('completed', 0)->first();
                $loan_installments = LoanInstallment::where('loan_id', $loan->id)->latest()->first();

                $to = \Carbon\Carbon::createFromFormat($loan->approved_date);
                $from = \Carbon\Carbon::createFromFormat($loan_installments->this_month);
                $net_installment_month = $to->diffInMonths($from);

                if($loan_installments == '') {
                    // user doesn't give first installment
                    $saving = SavingAcount::where('user_id', $user->id)->latest()->first();
                    $saving->total = $saving->total - 20;
                    $saving->save();

                    $username = "Alauddin101";
                    $hash = "4f9ec55ab0531a44a466910119d97847";
                    $numbers = $user->mobile_number; //Recipient Phone Number multiple number must be separated by comma
                    $message = '20tk has been deducted for your late of Loan from saving. Thank you! Your current saving is '.$saving->total;

                    $params = array('app'=>'ws', 'u'=>$username, 'h'=>$hash, 'op'=>'pv', 'unicode'=>'1','to'=>$numbers, 'msg'=>$message);

                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL, "http://alphasms.biz/index.php?".http_build_query($params, "", "&"));
                    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

                    $response = curl_exec($ch);
                    curl_close ($ch);
                }   elseif($loan_installments->amount < $net_installment_month * $loan->perInstallmentAmount) {
                    $saving = SavingAcount::where('user_id', $user->id)->latest()->first();
                    $saving->total = $saving->total - 20;
                    $saving->save();

                    $username = "Alauddin101";
                    $hash = "4f9ec55ab0531a44a466910119d97847";
                    $numbers = $user->mobile_number; //Recipient Phone Number multiple number must be separated by comma
                    $message = '20tk has been deducted for less amount then per installment amount of Loan from saving. Thank you! Your current saving is '.$saving->total;

                    $params = array('app'=>'ws', 'u'=>$username, 'h'=>$hash, 'op'=>'pv', 'unicode'=>'1','to'=>$numbers, 'msg'=>$message);

                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL, "http://alphasms.biz/index.php?".http_build_query($params, "", "&"));
                    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

                    $response = curl_exec($ch);
                    curl_close ($ch);
                }   else {
                    return 0;
                }
            }

Model

public function businessLoans() {
        return $this->hasMany('App\BusinessLoan');
    }

public function hasBusinessLoans() {
        return $this->businessLoans->flatten()->pluck('user_id')->last();
    }

They say erorr is in this line

if($user->hasBusinessLoans() == $user_id) {

But it outputs

dd($user->hasBusinessLoans()) =3
``
Activity icon

Awarded Best Reply on Laravel Showing Json While Storing Data

Please explain. I don't know what to do

Activity icon

Replied to Laravel Showing Json While Storing Data

Please explain. I don't know what to do

Activity icon

Started a new Conversation Laravel Showing Json While Storing Data

This is happening on cPanel not from localhost.

user Record Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Illuminate\Support\Str;

use Auth;

use App\ServiceCharge;

use App\ForgetUser;

use App\UserNotification;

use DB;

use App\User;

class UserRecordController extends Controller
{
    public function index() {
        if(Auth::user() == '') {
            return view('index');
        }   else {
            $user = UserNotification::where('user_id', Auth::user()->id)->first();
            return view('index', [
                'user' => $user
            ]);
        }
    }

    public function create() {
        return view('registration.index');
    }

    public function store(Request $request) {
        $this->validate($request, [
            'name' => 'required',
            'mobile_number' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/',
            'fathers_name' => 'required',
            'mothers_name' => 'required',
            'date_of_birth' => 'required',
            'address' => 'required',
            'thana' => 'required',
            'NID_or_birth_certificate_number' => 'required',
         ]);

         $user = User::where('mobile_number',$request->mobile_number)->first();

         if($user == '') {
            if($request->refer_account_number == null) {
                $user = User::select('mobile_number')->get();
                $user = new User();
                $digits = 5;
                $date = $request->date_of_birth;
                $token = rand(pow(10, $digits-1), pow(10, $digits)-1);

                $user->name = $request->input('name');
                $user->mobile_number = $request->input('mobile_number');
                $user->fathers_name = $request->input('fathers_name');
                $user->mothers_name = $request->input('mothers_name');
                $user->date_of_birth =  $request->date_of_birth;
                $user->address = $request->input('address');
                $user->thana = $request->input('thana');
                $user->nominee_name = $request->input('nominee_name');
                $user->nominee_address = $request->input('nominee_address');
                $user->NID_or_birth_certificate_number = $request->input('NID_or_birth_certificate_number');
                $user->password = \Hash::make($token);
                $user->refer_account_number = $request->refer_account_number;


                if($request->hasFile('image')) {
                    $user_file = $request->file('image');
                    $extension = $user_file->getClientOriginalExtension();
                    $fileName = time() . '.' .$extension;
                    $user_file->move('storage/profile-image', $fileName);
                    $user->image = $fileName;
                }   else {
                    return $request;
                    $user->image = ' ';
                }

                if($request->hasFile('nid_image')) {
                    $nid_file = $request->file('nid_image');
                    $extension = $nid_file->getClientOriginalExtension();
                    $fileName = time() . '.' .$extension;
                    $nid_file->move('storage/nid_or_birth_certificate_image', $fileName);
                    $user->nid_image = $fileName;
                }   else {
                    return $request;
                    $user->nid_image = ' ';
                }

                if($request->hasFile('nominee_nid')) {
                    $nid_file = $request->file('nominee_nid');
                    $extension = $nid_file->getClientOriginalExtension();
                    $fileName = time() . '.' .$extension;
                    $nid_file->move('storage/nid_or_birth_certificate_image', $fileName);
                    $user->nominee_nid = $fileName;
                }   else {
                    return $request;
                    $user->nominee_nid = ' ';
                }
                $user->save();

                $notification = new UserNotification();
                $notification->user_id = $user->id;
                $notification->status = 'Thanks for Registration. your password is '.$token;

                $notification->save();

                return redirect('/')->with('status', 'Wait for Authity to validate. Your password is '.$token);
             }  else {
                $user = new User();

                $date = $request->date_of_birth;
                $token = Str::random(5);

                $user->name = $request->input('name');
                $user->mobile_number = $request->input('mobile_number');
                $user->fathers_name = $request->input('fathers_name');
                $user->mothers_name = $request->input('mothers_name');
                $user->date_of_birth =  $request->date_of_birth;
                $user->address = $request->input('address');
                $user->thana = $request->input('thana');
                $user->NID_or_birth_certificate_number = $request->input('NID_or_birth_certificate_number');
                $user->password = \Hash::make($token);
                $user->refer_account_number = $request->refer_account_number;

                if($request->hasFile('image')) {
                    $user_file = $request->file('image');
                    $extension = $user_file->getClientOriginalExtension();
                    $fileName = time() . '.' .$extension;
                    $user_file->move('storage/profile-image', $fileName);
                    $user->image = $fileName;
                }   else {
                    return $request;
                    $user->image = ' ';
                }

                if($request->hasFile('nid_image')) {
                    $nid_file = $request->file('nid_image');
                    $extension = $nid_file->getClientOriginalExtension();
                    $fileName = time() . '.' .$extension;
                    $nid_file->move('storage/nid_or_birth_certificate_image', $fileName);
                    $user->nid_image = $fileName;
                }   else {
                    return $request;
                    $user->nid_image = ' ';
                }
                $user->save();

                $notification = new UserNotification();
                $notification->user_id = $user->id;
                $notification->status = 'Wait for Authity to validate. Your password is '.$token;

                $notification->save();

                return redirect('/')->with('status', 'Wait for Authity to validate. Your password is '.$token);
             }
         }  else if($user->mobile_number == $request->mobile_number) {

            return redirect('/')->with('status', 'Same Informtation');
         }  else {
            return redirect('/')->with('status', 'Incorrect Informtation');
         }
    }

    public function login(Request $request) {
        $request->validate([
            'mobile_number' => 'required',
            'password' => 'required'
        ]);
        $password = \Hash::make($request->password);

        $user = User::where("mobile_number", $request->mobile_number)->first();

        $credentials = $request->only('mobile_number', 'password');

        if (Auth::attempt($credentials)) {
            // Authentication passed...
            if($user->approved == 1) {
                return redirect('/');
            }   else {
                return redirect('/login')->with('status', 'wait for authority to approve');
            }
        }else{
            return redirect('/login')->with('status', 'Incorrect Password');
        }
    }


    public function logout() {
         auth()->logout();

         return redirect('/');
    }

    public function show(Request $request) {
        $user = User::where('id', $request->id)->first();
        return view('userProfile.index', [
            'user'=>$user
        ]);
    }

    public function update(Request $request) {
        $id = $request->id;
        $user = User::find($id);

        $user->name = $request->name;
        $user->mobile_number = $request->mobile_number;
        $user->fathers_name = $request->fathers_name;
        $user->mothers_name = $request->mothers_name;
        $user->date_of_birth =  $request->date_of_birth;
        $user->address = $request->address;
        $user->thana = $request->thana;
        $user->nominee_name = $request->nominee_name;
        $user->nominee_nid = $request->nominee_nid;
        $user->NID_or_birth_certificate_number = $request->NID_or_birth_certificate_number;
        $user->refer_account_number = $request->refer_account_number;
        $user->password = User::select('password')->where('id', $request->id)->first();

        if($request->image == '') {
            $image = User::select('image')->where('id', $request->id)->first();
            $user->image = $image->image;
        }   else {
            $user->image = $request->image;
        }

        if($request->nid_image == '') {
            $nid_image = User::select('nid_image')->where('id', $request->id)->first();
            $user->nid_image = $nid_image->nid_image;
        }   else {
            $user->nid_image = $request->nid_image;
        }

        $user->save();
        return redirect('/')->with('success', 'Your Information has updated');
    }

    public function forgetPassIndex() {
        return view('user.forgetPass');
    }

    public function forgetPassStore(Request $request) {
        $user = User::where('mobile_number',$request->mobile_number)->first();
        if($user == "") {
            dd('incorrect mobile number');
        }   else {
            $digits = 5;
            $token = rand(pow(10, $digits-1), pow(10, $digits)-1);

            $forget_user = new ForgetUser();
            $forget_user->user_id = $user->id;
            $forget_user->token = $token;
            $forget_user->save();

            $user->password = \Hash::make($token);
            $user->save();

            return redirect('/')->with('status', 'Manually verify by calling 01111111 number');
        }
    }

    public function removeNotification(Request $request) {
        DB::table('user_notifications')->where('user_id', '=', $request->id)->delete();

        return redirect('/');
    }
}

user Model

protected $hidden = [
        'password', 'remember_token',
    ];

    public function roles() {
        return $this->belongsToMany('App\Role');
    }

    public function checkAdmin() {
        return $this->roles->flatten()->pluck('name')->first();
    }

    public function checkRole() {
        return $this->roles->flatten()->pluck('id')->first();
    }

    public function savings() {
        return $this->hasMany('App\SavingAcount');
    }

    public function checkTotal() {
        return $this->savings->flatten()->pluck('total')->last();
    }

    public function hasSavings() {
        return $this->savings->flatten()->pluck('user_id')->last();
    }

    public function savingAmount() {
        return $this->savings->flatten()->pluck('total')->last();
    }
Oct
24
1 month ago
Activity icon

Replied to Can't Update A Boolean Value

Thank you so much

Activity icon

Started a new Conversation Can't Update A Boolean Value

Controller

public function g_acceptB(Request $request) {
        $garantors = DB::table('garantors')->where('loan_method', 'business_loan')->where('g_mobile_number', Auth::user()->mobile_number)->get();

        foreach ($garantors as $key => $garantor) {
            if($garantor->g_approved == 0) {
                $garantor->g_approved = 1;
                $garantor->save();

                return redirect('/dashboard')->with('status', 'loan accepted');
            }   else {
                return redirect('/admin')->with('status', 'Already Approved');
            }
        }
    }

Here garantor->save() doesn't work.

Assoc class

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Garantor extends Model
{
    protected $fillable = [
        'loan_id', 'loan_method', 'g_name', 'g_mobile_number', 'g_approved'
    ];

}
Activity icon

Replied to Insert Multiple Datas From An Array To Database

Can you give a short example... It really helps me then. Thank you

Activity icon

Started a new Conversation Insert Multiple Datas From An Array To Database

$garantor = new Garantor();

foreach($request->g_name as $name) {
                                foreach($request->g_account_no as $number) {
                                    $garantor->g_name = $name;
                                    $garantor->g_mobile_number = $number;
                                    $garantor->save();
                                }
                            }

It stores just one data. I don't know what is the problem

Oct
23
1 month ago
Activity icon

Replied to Laravel Request Array Doesn't Read All Inputs

<input type="text" name="g_name[]" placeholder="Gaurantor Account Number" required autofocus>
                                    @error('g_name')
                                        <span class="text-danger">{{ $message }}</span>
                                    @enderror
                                    <input type="text" name="g_account_no[]" placeholder="Gaurantor Account Number" required autofocus>
                                    @error('g_account_no')
                                        <span class="text-danger">{{ $message }}</span>
                                    @enderror

BUt I call it

Activity icon

Replied to Laravel Request Array Doesn't Read All Inputs

g_name[] is the garantor name

Activity icon

Replied to Laravel Request Array Doesn't Read All Inputs

Full form

@extends('layouts.app')

@section('content')
    <!-- Hero Section end -->
	<section class="hero-section">
		<div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <h2 class="mb-4 text-white text-center">Fill all the form for Business Loan</h2>
                </div>
            </div>
			<div class="row">
				<div class="col-lg-12">
					<form class="hero-form" method="post" action="/business_loan/{{Auth::user()->id}}" enctype="multipart/form-data">
                        @csrf
                        <input type="text" name="name" placeholder="Name of your business" required autofocus>
                        @error('name')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror

                        <input type="text" name="address" placeholder="Address of your business" required autofocus>
                        @error('address')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror

                        <input type="text" name="contact_no" placeholder="Contact Number of your business" required autofocus>
                        @error('contact_no')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror

                        <input type="text" name="category" placeholder="Enter Business Category" required autofocus>
                        @error('category')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror

                        <input type="text" name="exp" placeholder="Experience in Business" required autofocus>
                        @error('exp')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror

                        <input type="text" name="capital" placeholder="Capital of your business" required autofocus>
                        @error('capital')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror

                        <input id="amount" type="text" name="amount" placeholder="Loan Amount"  required autofocus>
                        @error('amount')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror

                        <label class="text-white" for="installments">Installments Maximum month : 10</label>
                        <input id="installments" type="text" name="installments" placeholder="Loan installments"  required autofocus>
                        @error('installments')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror

                        <h5 class="text-white">Per Installment Amount: <span style="color: dodgerblue" id="perInstallmentAmount"></span></h5>

                        <hr>
                        <h3 class="text-white mb-3">Minimum one Gaurantor is required for any kind of loan</h3>

                        <span class="addRowCol">
                            <div class="row">
                                <div class="col-md-11">
                                    <input type="text" name="g_name[]" placeholder="Gaurantor Account Number" required autofocus>
                                    @error('g_name')
                                        <span class="text-danger">{{ $message }}</span>
                                    @enderror
                                    <input type="text" name="g_account_no[]" placeholder="Gaurantor Account Number" required autofocus>
                                    @error('g_account_no')
                                        <span class="text-danger">{{ $message }}</span>
                                    @enderror
                                </div>
                                <div class="col-md-1">
                                    <a class="btn btn-info addRow text-white font-weight-bold">Add</a>
                                </div>
                            </div>
                        </span>
                        <script type="text/javascript">
                            $('.addRow').on('click', function() {
                                addRow();
                            });
                            $('span').on('click', '.removeRow', function() {
                                $(this).parent().parent().remove();
                            });
                            function addRow() {
                                var tr = '<div class="row">'+
                                            '<div class="col-md-11">'+
                                            '<input type="text" placeholder="Gaurantor Name" class="mt-3" class="form-control">'+
                                            ' @error('g_name')'+
                                            '<span class="text-danger">{{ $message }}</span>'+
                                            '@enderror'+
                                            '<input type="text" name="g_account_no[]" placeholder="Gaurantor Account Number" required autofocus>'+
                                            '@error('g_account_no')'+
                                            '<span class="text-danger">{{ $message }}</span>'+
                                            '@enderror'+
                                            '</div>'+
                                            '<div class="col-md-1">'+
                                            '<a class="btn btn-danger removeRow text-white font-weight-bold">Remove</a>'+
                                            '</div>'+
                                        '</div>';
                                $('.addRowCol').append(tr);
                            }
                        </script>
                        <button type="submit" class="site-btn">Apply</button>
					</form>
				</div>
			</div>
		</div>
		<div class="hero-slider owl-carousel">
			<div class="hs-item set-bg" data-setbg="img/hero-slider/1.jpg"></div>
			<div class="hs-item set-bg" data-setbg="img/hero-slider/2.jpg"></div>
			<div class="hs-item set-bg" data-setbg="img/hero-slider/3.jpg"></div>
		</div>
    </section>
    <script>
        $('input').keyup(function(){ // run anytime the value changes
            var amount  = Number($('#amount').val());
            var installments  = Number($('#installments').val());   // get value of field

            $('#perInstallmentAmount').html(amount / installments); // add them and output it
        // add them and output it
        });
    </script>


	<!-- Hero Section end -->
@endsection



controller

public function businessLoanCreate(Request $request) {
        dd($request);
}
Activity icon

Replied to Laravel Request Array Doesn't Read All Inputs

I am validating also

Activity icon

Replied to Laravel Request Array Doesn't Read All Inputs

I give two data there. But it shows one

Activity icon

Replied to Laravel Request Array Doesn't Read All Inputs

I give two values on the form. But g_account_name working well but g_name won't

Activity icon

Started a new Conversation Laravel Request Array Doesn't Read All Inputs

I give 2 inputs in the form but it doesn't read

<input type="text" name="g_name[]" placeholder="Gaurantor Account Number" required autofocus>
                                    @error('g_name')
                                        <span class="text-danger">{{ $message }}</span>
                                    @enderror
                                    <input type="text" name="g_account_no[]" placeholder="Gaurantor Account Number" required autofocus>
                                    @error('g_account_no')
                                        <span class="text-danger">{{ $message }}</span>
                                    @enderror

Output of dd($request);

"g_name" => array:1 [▼
        0 => "karim"
      ]
      "g_account_no" => array:2 [▼
        0 => "01616021103"
        1 => "123"
      ]
Oct
19
1 month ago
Activity icon

Replied to Call To A Member Function Save() On Array

I want to find that particular index to update total value. So I need to work with array

Activity icon

Replied to Call To A Member Function Save() On Array

I did but index becomes an undefined variable then

Activity icon

Started a new Conversation Call To A Member Function Save() On Array

I want to update the savings table. But cant get rid of this error

public function updateSavings(Request $request) {
        $id = $request->id;
        $savings = SavingAcount::find($id);

        $savings->mobile_number = $request->mobile_number;
        $savings->method = $request->method;
        $savings->tracking_number = $request->tracking_number;
        $savings->amount = $request->amount;
        $savings->user_id = $request->user_id;
        $savings->approved = 1;

        // $row = count(SavingAcount::select('amount')->where('user_id', $user->id)->get());

        if($request->total == $request->amount) {
            $savings->total = $request->amount;
        }   else {
            $user = SavingAcount::select('amount')->where('tracking_number', $request->track)->first();

            $updated_amount = (int)$request->amount - $user->amount;

            $users = SavingAcount::where('user_id', $request->user_id)->orderBy('created_at', 'asc')->get()->toArray();

            foreach($users as $key => $user) {
                if($user['total'] == $request->total) {
                    $index = $key;
                }
            }

            $savings->total = $request->total + $updated_amount;

            foreach($users as $key => $user) {
                if ($key < $index) continue;
                $user['total'] = $user['total'] + $updated_amount;

                $user->save();
            }
        }
        dd($savings);
        $savings->save();

        return redirect('/admin/savings')->with('status', 'savings Updated');
    }
Activity icon

Replied to Edit Amount And Calculate Total

Store function

public function store(Request $request) {
        if($request->phone_number == '') {
            $user = User::find($request->id);
            if (Hash::check($request->password, $user->password)) {
                $savings = new SavingAcount();

                $savings->user_id = $user->id;
                $savings->mobile_number = $user->mobile_number;
                $savings->tracking_number = $request->tracking_number;
                $savings->method = $request->method;
                $savings->amount = $request->amount;
                $row = count(SavingAcount::select('amount')->where('user_id', $user->id)->get());

                if($row == 0) {
                    $savings->total = $request->amount;
                }   else {
                    $prev_amount = SavingAcount::select('total')->where('user_id', $user->id)->latest()->first();
                    $savings->total = $request->amount + $prev_amount->total;
                }

                $savings->save();

                return redirect('/')->with('status', 'You Saving is added. Wait for authority to approve');
            }   else {
                return redirect('/')->with('status', 'Your Password is Incorrect');
            }
        }   else {
            $user = User::where('mobile_number',$request->phone_number)->first();

            if($user == '') {
                return redirect('/')->with('status', 'Incorrect Information');
            }   else {
                if (Hash::check($request->password, $user->password)) {
                    $savings = new SavingAcount();

                    $total = 0;

                    $savings->user_id = $user->id;
                    $savings->mobile_number = $user->mobile_number;
                    $savings->tracking_number = $request->tracking_number;
                    $savings->amount = $request->amount;
                    $savings->method = $request->method;
                    $row = count(SavingAcount::select('amount')->where('user_id', $user->id)->get());

                    if($row == 0) {
                        $savings->total = $request->amount;
                    }   else {
                        $prev_amount = SavingAcount::select('total')->where('user_id', $user->id)->latest()->first();
                        $savings->total = $request->amount + $prev_amount->total;
                    }

                    $savings->save();

                    return redirect('/')->with('status', 'You Saving is added. Wait for Authority to approve');
                }   else {
                    return redirect('/')->with('status', 'Your Password is Incorrect');
                }
            }
        }
    }
Activity icon

Replied to Edit Amount And Calculate Total

I am using plain laravel 7.0 Of course I Can. This is a store form data and now I want to edit this. but the thing is I can edit. But I don't know how I calculate the total value..

Activity icon

Replied to Edit Amount And Calculate Total

This is a edit form..

Activity icon

Started a new Conversation Edit Amount And Calculate Total

I can't find the logic behind this. Can anyone help me to sort out?

amount		total 
500			500
500			1000
2000		3000

after editing, total value should change automatically.

Oct
17
1 month ago
Activity icon

Replied to Laravel Update() Function Not Working

what.. can't understand

Activity icon

Replied to Laravel Update() Function Not Working

Thank you so much. I fixed the issue..

Activity icon

Replied to Laravel Update() Function Not Working

$savings->mobile_number = $request->mobile_number;
        $savings->method = $request->method;
        $savings->tracking_number = $request->tracking_number;
        $savings->amount = $request->amount;
        $savings->total = $request->total;
        $savings->user_id = $request->user_id;
        $savings->approved = 1;

        $savings->save();

on total and user_id. It comes from wildcard. this is not form data...

Activity icon

Replied to Laravel Update() Function Not Working

I am using it on the controller

Activity icon

Replied to Laravel Update() Function Not Working

Route::put('/admin/savings/update/{user_id}/{total}', '[email protected]');
Activity icon

Replied to Laravel Update() Function Not Working

i know. But save method making new record instead of updating

Activity icon

Replied to Laravel Update() Function Not Working

Even cut the validation code

public function updateSavings(Request $request,  SavingAcount $savings) {
        $savings->mobile_number = $request->mobile_number;
        $savings->method = $request->method;
        $savings->tracking_number = $request->tracking_number;
        $savings->amount = $request->amount;
        $savings->total = $request->total;
        $savings->user_id = $request->id;
        $savings->approved = 1;

        $savings->update();

        return redirect('/admin/savings')->with('status', 'savings Updated');
    }
Activity icon

Replied to Laravel Update() Function Not Working

I solved that. But still not updating

Activity icon

Replied to Laravel Update() Function Not Working

Still not updating

Activity icon

Replied to Laravel Update() Function Not Working

But it shows Exception

Activity icon

Replied to Laravel Update() Function Not Working

when i save this. it makes new record. But I want to update

Activity icon

Replied to Laravel Update() Function Not Working

everythings there

Activity icon

Replied to Laravel Update() Function Not Working

Amount is not updating

Activity icon

Started a new Conversation Laravel Update() Function Not Working

Class

protected $fillable = [
        'mobile_number',
        'method',
        'tracking_number',
        'amount',
        'user_id',
        'total',
        'approved'
    ];

Controller

    public function updateSavings(Request $request) {
        $request->validate([
            'mobile_number' => 'required',
            'method' => 'required',
            'tracking_number' => 'required',
            'amount' => 'required',
        ]);

        $savings = new SavingAcount();

        $savings->mobile_number = $request->mobile_number;
        $savings->method = $request->method;
        $savings->tracking_number = $request->tracking_number;
        $savings->amount = $request->amount;
        $savings->total = $request->total;
        $savings->user_id = $request->id;
        $savings->approved = 1;

        $savings->update();

        return redirect('/admin/savings')->with('status', 'savings Updated');
    }
Oct
15
1 month ago
Activity icon

Replied to How To Style The Redirected Message

Thank you so much

Activity icon

Replied to How To Style The Redirected Message

It also don't work... I tried this