lundi 29 juillet 2019

Having problem with retriving json data in laravel

I'm working on a laravel project and i'm getting JSON error. I've try few options to solve the issue but did not come up with any solutions.

In this project I've to send multiple data into database onder one "ID". In that ID there are at list 10 data need to insert. So I used JSON format. It saves ok but getting error when I try to pull data.

Here is my code

Controller :

public function newExpenses(Request $request){

        $Jexpenses = new Jexpenses;

        $json = array(
            'des' => $request->description,
            'valu' => $request->expenses
        );

        $Jexpenses->voucher = $request->voucher_no;
        $Jexpenses->date = $request->date;
        $Jexpenses->description = json_encode($json);
        $Jexpenses->expenses = $request->total;
        $Jexpenses->remarks = $request->remark;

        if($Jexpenses->save()){
            $notification = array(
                'message' => 'Expenses Saved',
                'alert-type' => 'success'
            );
        }

        return redirect()->back()->with($notification);
    }

result :

{"des":["Jon","Sam","Pitter"],"valu":["20","30","15"]}

Return Controller:

public function expenses(){
        $data = array(
            'title' => 'Expenses',
            'expenses' => Jexpenses::all()
        );

        return view('expenses.expenses')->with($data);
    }

html :

@foreach ($expenses as $key => $getData)


    


    <tr>
        <td> </td>
        <td> </td>
        <td> </td>
        @foreach ($array->description as $k => $v)
           <td></td>
            <td></td>
         @endforeach
        <td></td>
        <td></td>
    </tr>
 @endforeach

it should be work fine but getting error

error:

syntax error, unexpected '<' (View: C:\xampp\htdocs\acSoft\resources\views\expenses\expenses.blade.php

Need some help. Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire