Skip to content

Instantly share code, notes, and snippets.

@sabid
Last active July 20, 2020 21:26
Show Gist options
  • Save sabid/14bf8a4a03368c1e6e2ac39cb7c94ea2 to your computer and use it in GitHub Desktop.
Save sabid/14bf8a4a03368c1e6e2ac39cb7c94ea2 to your computer and use it in GitHub Desktop.
// resources\view\products\index.blade.php
@section('content')
// $products
@foreach ($products as $product)
{{ $product->name; }}
@endforeach
@endsection
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
// protected $fillable = [
// 'name',
// 'description',
// 'price'
// ];
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];
}
<?php
namespace App\Http\Controllers;
use App\Product;
use Illuminate\Http\Request;
class ProductController extends Controller
{
/**
* Display a listing of the product.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$products = collect([
new Product([
'id' => 1,
'name' => 'Juego de sala',
'price' => 6000
]),
new Product([
'id' => 2,
'name' => 'Estufa',
'price' => 9000
])
]);
//dd($products);
return view('products.index', [
'products' => $products
]);
}
}
/* Route\web.php */
/*
* Resource Controller
* El nombre en plural y el nombre del controlador en singular,
* unido con la palabra controller
*/
Route::resource('products', 'ProductController');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment