I have two tables for sellers and products. Each seller can post their product. I've already done the post method.
How can I know each product's seller, and how can I display it?
class ProductController extends Controller
{
public function index()
{
return view('ps.products.create');
}
public function store(Request $request)
{
$product = new Product;
$product->name = $request->name;
$product->description = $request->description;
$product->type = $request->type;
$product->size = $request->size;
$product->price = $request->price;
$product->image = $request->image;
$product->save();
return view('pshome');
}
public function show()
{
$id = DB::table('product')->get();
return view('viewproduct', ['id' => $id]);
}
}
Seller model
class Ps extends Authenticatable{ use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name','lastname','email', 'password', 'username','phone',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];}
Product model
class Product extends Model {
public $table = "Product";
protected $fillable = ['name','description','size','image','price','type'];
protected $hidden = ['password', 'remember_token'];
}
auth()->id()
in the products table? – Devon