gpt4 book ai didi

How to show database from two different tables in one page on Laravel 10?(如何在一个页面上显示两个不同表中的数据库?)

转载 作者:bug小助手 更新时间:2023-10-28 20:32:24 27 4
gpt4 key购买 nike



So, I had supplier and Materials table that i want to show the data on the same pages? I want to make ERP for store material data

所以,我有供应商和材料表,我想在同一页上显示数据?我想做仓库物料数据的ERP


Supplier Models :

供应商型号:


namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\GudangMaterial;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class Supplier extends Model
{
use HasFactory;
protected $table='supplier';

protected $fillable = [
'id',
'nama',
'alamat',
'email',
'noTelp',
'update_at',
'create_at',
];

public function gudangproduk()
{
return $this->belongsToMany(GMaterial::class)->withTimestamps();
}
}


Material Models :

材料模型:


namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class GMaterial extends Model
{
use HasFactory;
protected $table = 'gmaterial';

protected $fillable = [

'name',
'kode',
'jmlh',
'jmlh_min',
'satuan',

];

public function supply() {

return $this->belongsToMany(Supplier::class, 'group_material');
}
}


The Controller :

控制器:


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\GMaterial;
use App\Models\Supplier;

public function material() {

$bahan = gmaterial::all();

return view('master.material')->with('bahan', $bahan);
}

public function simpanMaterial(Request $request) {

$bahan = new gmaterial;
$bahan->nama = $request->input('namaProduk');
$bahan->harga = $request->input('harga');
$bahan->stock = $request->input('stock');
$bahan->tanggal = $request->input('tanggal');
$bahan->save();

return redirect()->route('material')->with('success', 'Data berhasil disimpan!');
}

public function updateMaterial(Request $request,$id) {

$bahan['namaProduk'] = $request->nama;
$bahan['harga'] = $request->harga;
$bahan['stock' ]= $request->stock;
$bahan['tanggal'] = $request->tanggal;

gmaterial::whereId($id)->update($bahan);

return redirect()->route('material')->with('success', 'Data telah Di Update!');

}

public function hapusMaterial(Request $request,$id) {

$bahan = gmaterial::find($id);

if($bahan){
$bahan->delete();
}

return redirect()->route('material')->with('success', 'Data telah terhapus!');
}
}

Im try to using hasMany and dump the data but still show null.

我尝试使用hasMany和转储数据,但仍然显示空。


What i expecting is the data will show in the same page and i can add more data, delete data and Edit the data

我期望的是数据将显示在同一个页面上,我可以添加更多的数据,删除数据和编辑数据


Kode Material Name Material Supplier QTY QTY Min Satuan Action
1 Wooden Test 20 5 Pcs Delete Edit

KODE材料名称材料供应商数量最少萨团动作1木质测试20 5件删除编辑


更多回答
优秀答案推荐
更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com