2016-10-23 50 views
0

我越來越Laravel控制器中的另一個功能是被稱爲

ErrorException在ProjectController.php 41行:試圖讓非對象

我打電話delete_project的 財產()內我的控制器,但它似乎Laravel也呼籲get_project($ variable_here)方法

ProjectsController

public function get_project($slug_name){ 
    $project = Project::where('slug_name', $slug_name)->first(); 
    if ($project->user_id == Auth::user()->id) { 
     return view('project', ['project' => $project]); 
    }else { 
     return redirect('console'); 
    } 
} 

public function delete_project(){ 

} 

網絡路由

Route::get('/console', 'H[email protected]'); 

Route::get('project/{slug_name}', '[email protected]_project'); 

Route::get('get_projects', '[email protected]_projects'); 

Route::post('create_new_project', '[email protected]_new_project'); 

Route::post('/delete_project', '[email protected]_project'); 
+0

請顯示'get_project'路線。 –

+0

哎呀對不起,我忘了那條線。 Route :: get('get_projects','UserController @ get_projects'); – mariozawa

+0

路線看起來不錯。嘗試使用'php artisan route:clear'命令清除路由緩存。 –

回答

0

通過我的形式加入這一輸入解決發送刪除請求

<input type="hidden" name="_method" value="delete"> 

而改變delete_project所以我現在有我的網絡路線

Route::get('/project/{slug_name}', '[email protected]_project'); 
Route::delete('/project/{slug_name}', '[email protected]_project'); 
相關問題