我正在用 laravel 項目訓練我的作業(yè),這是我的問題:我有一個數(shù)據(jù)庫,其中包含Event名稱和與該數(shù)據(jù)庫的一系列關(guān)系,其中兩個是events_news,event_gallery哪個新聞更新工作正常,購買畫廊就行不通,我用同樣的方式處理新聞,我試過郵遞員,我只得到更新的響應(yīng),但沒有任何改變。這是我的事件模型:protected static function boot(){ parent::boot(); static::creating(function ($event){ $event->slug = str_slug($event->name); });}public function getRouteKeyName(){ return 'slug';}protected $with = ['galleries','news'];public function news(){ return $this->hasMany(EventNews::class);}public function galleries(){ return $this->hasMany(EventGallery::class);}public function getPathAttribute(){ return "/admin/events/$this->slug";}這是我的畫廊和新聞模型:我之前都使用了guarded,但我已經(jīng)在畫廊中添加了可填充的,看看它是否有效。class EventGallery extends Model{ protected $fillable = ['event_id', 'url', 'body', 'flag']; public function event() { return $this->belongsTo(Event::class); }} class EventNews extends Model { protected $guarded = []; public function event() { return $this->belongsTo(Event::class); }}這是我的控制器:public function update(Request $request, Event $event, EventGallery $eventGallery){ /I've tried this and got same result $eventGallery->update($request->all()); /I've tried this and still got the same result $eventGallery->update( [ 'url' => $request->url, 'body' => $request->body, 'flag' => $request->flag, ] ); return response('Updated', Response::HTTP_ACCEPTED);}應(yīng)用程序接口:Route::apiResource('/admin/events/{event}/gallery', 'Events\EventsPictureController');我將使用數(shù)據(jù)庫中的真實數(shù)據(jù)進行測試 http://127.0.0.1:8000/api/admin/events/international-2019/gallery/2它說已更新,但沒有任何改變。請幫我找到我的問題。我檢查了事件并正確導入而不是 Facade/Event。這是帶有 vue.js 的 SPA 應(yīng)用程序。和講師在控制器中注入了 Event 所以這就是為什么我像你看到的那樣做它。
1 回答

慕蓋茨4494581
TA貢獻1850條經(jīng)驗 獲得超11個贊
在挖掘我的問題之后,我剛剛改變了控制器 public function update(Request $request, Event $event, EventGallery $eventGallery)
到 public function update(Request $request, Event $event, EventGallery $gallery)
仍在尋找發(fā)生這種情況的原因。也許是因為我在我的事件模型中調(diào)用了畫廊
正如你在頂部看到的那樣,我輸入了畫廊,但由于我正在嘗試任何東西,我將函數(shù)模型更改為畫廊,但它沒有幫助,但是當我更改 $eventGallery 時,它起作用了。
- 1 回答
- 0 關(guān)注
- 174 瀏覽
添加回答
舉報
0/150
提交
取消