売り手と商品の2つのテーブルがあります。各売り手は商品を投稿することができます。私はすでに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
あなたの商品と売り手のモデルを見せていただけますか? –
こんにちはレオナルド、質問を編集しました –