Laravel Controller正在调用另一个函数

时间:2016-10-23 17:00:50

标签: laravel laravel-routing laravel-5.3

我正在

  

ProjectController.php第41行中的ErrorException:试图获取   非对象的属性

我在控制器中调用 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', 'HomeController@index');

Route::get('project/{slug_name}', 'ProjectController@get_project');

Route::get('get_projects', 'UserController@get_projects');

Route::post('create_new_project', 'ProjectController@create_new_project');

Route::post('/delete_project', 'ProjectController@delete_project');

1 个答案:

答案 0 :(得分:0)

通过在表单上添加输入来解决,以发送删除请求

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

并更改了delete_project路线,所以我现在在我的网络路线上有这个

Route::get('/project/{slug_name}', 'ProjectController@get_project');
Route::delete('/project/{slug_name}', 'ProjectController@delete_project');