我有兩個賣家和產品表。每個賣家可以發佈他們的產品。我已經完成了post方法。我如何獲得誰發佈產品
如何知道每個產品的賣家,以及如何顯示它?
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]);
}
}
賣家模型
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',
];}
產品型號
類產品擴展模式{
公共$表= 「產品」;
protected $ fillable = ['name','description','size','image','price','type'];
protected $ hidden = ['password','remember_token'];
}
商店'AUTH() - > ID()'在產品表? – Devon
你能告訴我們你的產品和賣家模型嗎? –
嗨萊昂納多,我已編輯的問題 –