Laravel 5.2 Return View from Controller

I have a view defined in the "admin" subdirectory, which is an editing form. On submission, this is transmitted to the controller with the following code:

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);
    };
}

It updates one OK header, but I always get

NotFoundHttpException in RouteCollection.php line 161:

Although the route that calls the edit (and works fine):

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

If you submit a form, make sure the route uses the message.

Route::post('/admin/editfront', 'ThisSiteController@updateSite');

If this is not a problem, can you show your form code and update route?

EDIT

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
source

, 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]);
  }
}

editfront route ThisSiteController@editSite.

action="{{ action('ThisSiteController@editSite') }}"

0

You are using a search query in a route, this can cause problems.

If you use the POST method on the form, change your route to:

Route::post('/admin/editfront',ThisSiteController@updateSite});

It would be very helpful if you can show the whole error message or route file.

0
source

Source: https://habr.com/ru/post/1651207/


All Articles