1

i am try to get data from database to my index page. i complete code for get data. but dose note show anything in my index page.

i import that model.

This is my controller code

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Model\admin\Product;


class UserController extends Controller
{
    function userIndex()
    {
        $products = Product::all();
        return view('user/index', compact('products'));
    }
    function userContact()
    {
        return view('user.contact');
    }
}

index file code

@foreach ($products as $product)
<li>{{ $product->index }}</li>
<li><div class="intro-item">
<figure>
<img src="{{ asset('user/img/intro/1.jpg')}}" alt="#">
</figure>
<div class="product-info">
    <h5>{{$product->product_name}}</h5>
    <p>{{$product->product_price}}</p>
<a href="#" class="site-btn btn-line">ADD TO CART</a>
</div>
</div>
</li>
@endforeach

i do note get any error or data.

Roman Syed
  • 27
  • 6
  • Possible duplicate of [PHP parse/syntax errors; and how to solve them?](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – aynber Jul 25 '19 at 16:08
  • sorry @aynber, its my typing mistake . but when i run this code, i do note get any error. – Roman Syed Jul 25 '19 at 16:17
  • Does using `/` in your `view()` work? Wouldn't it be `view('user.index', compact('products'));`? – brombeer Jul 25 '19 at 16:18
  • @kerbholz bro, i tried with / and also . , my view file ok, but do not get data from data base. – Roman Syed Jul 25 '19 at 16:25
  • 2
    `dd($products);` before returning your view to see if you get anything at all. Also, `proce` should be `price`? Make sure your namespaces are ok – brombeer Jul 25 '19 at 16:45
  • @kerbholz brother when i try this. when i try to print_r then i get the empty item (arrey) – Roman Syed Jul 25 '19 at 17:01
  • Do you have any data in your database for the products? Open tinker: `php artisan tinker` and try this: `$product = new Product;`, on the next line try this: `$product->get();`. What do you see now? – Majid Alaeinia Jul 25 '19 at 17:05
  • There is no issue with code provided above – Sahil Jain Jul 25 '19 at 17:26