How to retrieve value from the migrations and display them

86 Views Asked by At

I used this for my migrations.

<?php

use Anomaly\Streams\Platform\Database\Migration\Migration;

class SnipcartModuleProductsCreateProductsFields extends Migration
{

    /**
     * The addon fields.
     *
     * @var array
     */
    protected $fields = [
        'name' => 'anomaly.field_type.text',
        'description' => 'anomaly.field_type.text',
        'sku' => [
            'type' => 'anomaly.field_type.slug',
            'config' => [
                'slugify' => 'name',
                'type' => '-'
            ],
        ],
        'price'  => [
            "type"   => "anomaly.field_type.decimal",
            "config" => [
                "min"       => 0
            ]
        ],
        'image' => 'anomaly.field_type.file',
        'tags'  => [
            'type'   => 'anomaly.field_type.tags',
            'config' => [
                'free_input'    => true
            ]
        ]
        ];

}

Routing it from here

web.php

Route::get('/products', function () {
    return view('products','ProductsController@getProducts');
 }); 

Now How would I retrieve those values from here

ProductControllers.php

//name,description and price all the values should be pass to the products.blade.php

public function getProducts(){
    
    $products = [];
    return view('products', ['products' => $products]);
}

Then display it here

products.blade.php

         @if (products) 
                <div class="row">
                    @foreach ($products as $product)
                        <div class="col-sm-4">
                            <div class="card" style="margin-bottom: 2rem;">
                            
                            <div class="card-body">
                                <h4 class="card-title">{{ $product->name }}</h4>
                                <img />
                                <p class="card-text">{{ $product->description }}</p>
                                <a href="#" class="btn btn-primary">Buy for {{ $product->price }}</a>
                            </div>
                            </div>
                        </div>
                    @endforeach
                    
                </div>
            @endif
0

There are 0 best solutions below