簡體   English   中英

Laravel沒有模型[App \\ Topic]創建的查詢結果

[英]Laravel No query results for model [App\Topic] create

我正在嘗試獲取用戶能夠創建主題的視圖。 我在我的項目中多次這樣做但從未遇到過這個錯誤,因為所有其他的工作都很好。

我收到錯誤No query results for model [App\\Topic] create 這是代碼。

這是應該將用戶帶到視圖的鏈接。

        <div class="col s12">
            <div class="card">
                <div class="card-content clearfix">
                    <a href="{{ route('createtopic', ['theme_id' => $theme->id]) }}" class="waves-effect waves-light btn blue-grey darken-4">New topic <i class="material-icons right">edit</i></a>
                </div>
            </div>
        </div>

這些是此問題中使用的路由。

Route::get('/theme/{theme_id}/topics/create', 'TopicsController@create')->name('createtopic');
Route::post('/theme/{theme_id}/topics/create', 'TopicsController@store')->name('savetopic');

Controller方法創建。

dd('Hij is er ' . $id);

並且store方法為空,鏈接不顯示DumpDie方法,而是顯示錯誤。 因此,沒有必要發布我想要顯示的視圖,因為這不是問題所在。 提前致謝!

您需要了解路由和控制器方法的工作原理

Route::get('/theme/{theme_id}/topics/create', 'TopicsController@create')->name('createtopic');

當您點擊上述路線時,我的意思是你的瀏覽器中有例如yourdomain/theme/1/topics/create ,然后它將取代1替換theme_id ,它將轉到你的TopicsControllercreate方法,它將接受一個論點。

你的create方法應該是這樣的

public function create($id)
{
   dd($id);
}

在這里你將獲得1作為結果,因為你已經在你的網址而不是theme_id中傳遞了這個參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM