0
이 코드가 있습니다.Many to Many Ajax Laravel 5.2
public function items($subcategory_id){
$items = $this->ajax->items($subcategory_id);
return Response::json([
'success' => 'true',
'items' => $items
]);
}
당신이 많은 많은에 unit_id 참조를 볼 수 있습니다 당신은 자바 스크립트의 unit_id의 이름을 얻을 수를 조작 할 수있다. 루프를 만들어 자신 만의 배열을 만들거나 할 수있는 함수가 필요합니까? 내 저장소 코드는 다음과 같습니다.
public function items($subcategory_id){
$this->modelName = new Subcategory();
return $this->modelName->find($subcategory_id)->items;
}
내 모델
namespace App;
use Illuminate\Database\Eloquent\Model;
class Subcategory extends Model
{
protected $table = 'subcategories';
protected $fillable = [
'qty', 'desc', 'unit_price', 'ext_price'
];
public function items(){
return $this->belongsToMany('App\Item', 'item_subcategory', 'subcategory_id', 'item_id')->withTimestamps();
}
}
당신이해야 할 것은 열망로드를 사용합니다. 그러나 나는 당신의 모델과 관계가 무엇인지 이해하지 못합니다. 모델 코드 게시. – PawelMysior
public function items() { \t return $ this-> belongsToMany ('App \ Item', 'item_subcategory', 'subcategory_id', 'item_id') -> withTimestamps(); } – Rbex
json 구조를 자바 스크립트에 보내려면 어떻게해야합니까? – KmasterYC