0

I got this error when I deleted all recorded currency in my table, please tell me what's going on.

This my code in controller

    public function massDestroy(Request $request)
{
    if (! Gate::allows('currency_delete')) {
        return abort(401);
    }
    if ($request->input('ids')) {
        $entries = Currency::whereIn('id', $request->input('ids'))->get();

        foreach ($entries as $entry) {
            $entry->delete();
        }
    }
}

while this is my code in javascript.php

    @if (auth()->check())
    $('#moneyFormat').maskMoney({
        // The symbol to be displayed before the value entered by the user
        prefix:'{{ auth()->user()->currency->symbol }}',
        // The thousands separator
        thousands:'{{ auth()->user()->currency->money_format_thousands }}',
        // The decimal separator
        decimal:'{{ auth()->user()->currency->money_format_decimal }}'
    }); 

    $('#expense, #income').submit(function(){
        var value = $('#moneyFormat').maskMoney('unmasked')[0];
        $('#moneyFormat').val(value);
    });
    @endif
N-Jay
  • 43
  • 9
  • The current user has no currency. Check that currency exists before you try pulling data out of it. – aynber Dec 14 '18 at 16:40
  • sir can you please tell me what exactly to do because I dont get it, i'm newbie in programming. – N-Jay Dec 14 '18 at 16:44
  • Yes, ma'am, I sure can. `@if (auth()->check() && auth()->user() && auth()->user()->currency)`. It's best to check it down the line so it doesn't fail in the middle. – aynber Dec 14 '18 at 16:45
  • 1
    Possible duplicate of [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Dezza Dec 14 '18 at 16:49

1 Answers1

-1

Although this might not be a direct answer but an advice which is that we should always track data by dumping them using var_dump before using the data. It will reduce our errors.

toykam
  • 22
  • 3