2016-08-14 7 views
4

편집 양식 인 "admin"하위 디렉토리에 뷰가 정의되어 있습니다. 다음 코드를 컨트롤러에이 넘겨진다 제출하는 경우 :Laravel 5.2 컨트롤러에서보기 다시보기

class ThisSiteController extends Controller 
{ 
    public function updateSite(Request $request) 
    { 
     $thissite = DB::table('this_site')->where('id',1)->get(); 
     $thissite->headline = $request->headline; 
     $thissite->save(); 
     return view('admin.editfront')->with('site', $thissite); 
    }; 
} 

그것은 확인을 한 헤드 라인을 업데이트하지만 편집을 호출하는 경로가 있지만 난 항상

NotFoundHttpException in RouteCollection.php line 161: 

를 얻을 수 (그리고 잘 작동) :

Route::get('/admin/editfront', function() { 
    $thissite = DB::table('this_site')->where('id',1)->get(); 
    return view('admin.editfront')->with('site', $thissite); 
}); 
+0

예. db가 업데이트됩니다. 에러를주는 뷰를 호출하는 선입니다. – Jim

+0

아니요 - 저는 폼에서 컨트롤러 메서드를 호출하기 만합니다. – Jim

+0

@Jim 언제이 오류가 발생합니까? 양식을 제출 한 후 또는 양식을 제출하기 전에? – jaysingkar

답변

0

양식을 제출하는 경우 경로가 게시물을 사용하는지 확인하십시오.

문제가 있으면 양식 코드와 업데이트 경로를 표시 할 수 있습니까?

편집

class ThisSiteController extends Controller 
{ 
    public function updateSite(Request $request) 
    { 
     DB::table('this_site') 
      ->where('id',1) 
      ->update(['headline' => $request->input('headline')]); 
     $thissite = DB::table('this_site')->where('id',1)->first(); 
     return view('admin.editfront')->with('site', $site); 
    }; 
} 
+0

양식을

으로 변경했지만 여전히 오류가 발생했습니다 – Jim

+0

미안해. Fiorm은 이제 form = "form1"method = "post"action = "{{/ admin/editf ront}}"> ThisSiteController.php 줄에서 ErrorException을 얻고 있습니다. 16 : 비 객체의 속성을 얻으려고합니다. "$ this-> headline = $ request-> headline;을 참조 할 때. – Jim

+0

은'get()'이 결과 배열을 반환하기 때문에 thats입니다. 'find (1)'또는'$ thissite [0] -> headline'을 사용하십시오 –

0

난 당신이뿐만 아니라 방법을 컨트롤러로 편집 작업을 이동 UpdateSite 디 방법을 다음과 같이 변경 업데이트의 문제를 해결해야 권하고 싶습니다. 모델을 사용했다면 훨씬 간단했을 것입니다.

class ThisSiteController extends Controller{ 

    public function updateSite(Request $request){ 
    $thissite = DB::table('this_site')->where('id',1)->update(['headline' => $request->get('headline')]); 

    return view('admin.editfront',['site' => $thissite]); 
    } 

    public function editSite(){ 
    $thissite = DB::table('this_site')->where('id',1)->first(); 
    return view('admin.editfront',['site' => $thissite]); 
    } 
} 

[email protected] 방법으로 경로를 수정하십시오.

양식 조치에 대한

당신은 당신이 경로에 GET 요청을 사용하는 action="{{ action('[email protected]') }}"

0

할 수 있습니다, 이것은 문제의 원인이 될 수 있습니다. 당신이 오류 메시지 또는 경로 파일 전체를 보여줄 수 있다면 매우 유용 할 것이다

Route::post('/admin/editfront',[email protected]}); 

:

당신이 형태로 POST 방식을 사용하는 경우에 경로를 변경합니다.