dimanche 10 novembre 2019

How can I display the array as table format in laravel view

How can I display below arrays in table format in Laravel? Below is the sample arrays.

{"1":{"name":"Bajiya","quantity":2,"price":"34.00"},"2":{"name":"Gulha","quantity":2,"price":"3.00"}}

{"1":{"name":"Bajiya","quantity":2,"price":"34.00"},"2":"name":"Gulha","quantity":2,"price":"3.00"}}

{"1":{"name":"Bajiya","quantity":3,"price":"34.00"},"2":{"name":"Gulha","quantity":3,"price":"3.00"},"3":{"name":"kavaabu","quantity":2,"price":"2.00"}}

{"1":{"name":"Bajiya","quantity":2,"price":"34.00"}}

This is my Controller Function which returns the array to blade.

public function cartsIndex(Request $request)
{
    $carts = Cart::all('cart');
    $carts = json_decode($carts);
    $carts = Arr::pluck($carts, 'cart');
    return view('cartsIndex')->with(["carts" => $carts]);
}

This is my View File

@extends('layouts.app')
@section('content')
@foreach ($carts as $cart => $name)
     <br>
@endforeach
@endsection

And this is my Model File

namespace App;

use Illuminate\Database\Eloquent\Model;

class Cart extends Model
{
protected $fillable = ['cart',]; 
protected $casts = ['cart' =>'cart',];
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire