php - laravel eloquent orm view -
my ultimate goal print contents of table in database table in html using laravel's orm.
beyond know how configure database file, there other things need configure.
from understanding need 3 files. need make controller? if how work?
item class
route.php
views.php
here have far
item.php
<?php namespace app; use illuminate\database\eloquent\model; class item extends model { protected $table = 'items'; protected $primarykey = 'item_id'; public function products() { return $this->belongsto('item_id', 'item_name', 'item_cost'); } }
routes.php
<?php route::get('product', function() { $products = \app\items::all(); return view('items', $items); });
and have no idea how create view in html.
i know i'm off @ point, i've read documentation , still lost when reference things uri , have url in same sentence without defining or linking elsewhere in documentation.
actually, have declared eloquent orm
this:
class item extends model { // ... }
but using model/class
this:
$products = \app\items::all();
in case, \app\items
doesn't exist, should be:
$items = \app\item::all(); // <-- item not items return view('items', $items); // <-- $items not $products
you asked: do need make controller?
in case, no, it'll work fine anonymous
function using controller
better many reasons.
update:
create view in resources/views
items.blade.php
, can print out items through foreach
loop. check documentation.
Comments
Post a Comment