我被困在這里,我不確定最好的行動(dòng)方案目前我有一個(gè) blade 和 vue 組件組成一個(gè)儀表板。我有一個(gè)加載儀表板視圖的路由,以及另一個(gè)獲取 ID 詳細(xì)信息的路由(在事件發(fā)生時(shí)在儀表板內(nèi)調(diào)用)。這現(xiàn)在完美地工作。問(wèn)題是我希望能夠從外部訪問(wèn)第二條路線(如 site.com/status/12345)并默認(rèn)加載該 ID (12345) 的數(shù)據(jù)?,F(xiàn)在我點(diǎn)擊 site.com/status 并在創(chuàng)建頁(yè)面時(shí)調(diào)用它fetchEntries來(lái)獲取數(shù)據(jù),我根據(jù)該數(shù)據(jù)呈現(xiàn)一個(gè)帶有鏈接的表格,所以如果你點(diǎn)擊一個(gè)鏈接,它會(huì)將點(diǎn)擊條目的 ID 傳遞到 status/{id}獲取特定點(diǎn)擊條目的詳細(xì)信息。然后它將返回的數(shù)據(jù)加載到詳細(xì)信息屏幕中。我在這里要做的就是做到這一點(diǎn),以便如果我調(diào)用 status/12345 它會(huì)命中該路由和我的控制器details方法。site.com/status我知道我也可以在創(chuàng)建頁(yè)面時(shí)調(diào)用該函數(shù),但我想知道如何處理和之間的區(qū)別site.com/status/12345。我應(yīng)該在這里做什么,我該怎么做?這是我現(xiàn)在擁有的:控制器.phppublic function index() { return view('Entry.status');}public function details($id) { return json_encode(Entry::getDetails($id));}web.php(路線)Route::get('/Entry/status', 'Entry\EntryController@index') ->name('Entry.status');Route::get('/Entry/status/{id}', 'Entry\EntryController@details') ->name('Entry.status');狀態(tài).vuecreated() { this.fetchEntries(); },fetchEntries() { axios.get('/Entry/dashboard') .then(response => { this.events = response.data; }) .catch(function(error) { console.log(error) }) .finally(function() { })},getDetails(event) { this.detailId = event.taskt_id; axios.get('/Entry/status/' + this.detailId) .then(response => { ...}
1 回答

智慧大石
TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊
如果我正確理解你的問(wèn)題。我認(rèn)為你可以做這樣的事情。
public function details($id) {
if (request()->wantsJson()) {
return json_encode(Entry::getDetails($id));
}
return view('Entry.detail');
}
這是你想要的嗎?
- 1 回答
- 0 關(guān)注
- 115 瀏覽
添加回答
舉報(bào)
0/150
提交
取消