Home > other >  Laravel return page after deleted one row
Laravel return page after deleted one row

Time:12-07

how can I return to the same page after deleting something?

Controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Controllers\View;

class TableditControllerRolete extends Controller
{
    public function index(){
        $data = DB::table('Rolete')->get();
        return view('table_edit', compact('data'));
    }
    
    public function destroy($id){
        DB::delete('delete from Rolete where ProdusID = ?' ,[$id]);

    }
    

}

Web.php:

/*tabledit*/
Route::get('tabledit', 'TableditControllerRolete@index');
Route::get('delete/{id}','TableditControllerRolete@destroy');

And .blade:

<tbody>
                @foreach($data as $row)
                <tr>
                  <td>
                      <a href="$" class="btn btn-info" target="blank"><i class="fa fa-pencil"></i></a> 
                       <a href = 'delete/{{$row->ProdusID}}'  target="blank"><i ></i></a>
                  </td>
               
                </tr>
                @endforeach
              </tbody>
    

So , she deleted from my table, but dosen't return to the same page.

Thanks

CodePudding user response:

You can return something else, eg. a view:

   public function destroy($id){
    
    DB::delete('delete from Rolete where ProdusID = ?' ,[$id]);
    return View::make('path')->with('var',$var);

   }

the with() is optional. you can use with() if you want to pass some data to the view like record deleted Successful etc..

CodePudding user response:

Update your controller destroy() method as below,
return Redirect::back(); returns back to the previous page from where you triggered the method.

public function destroy($id){

       DB::delete('delete from Rolete where ProdusID = ?' ,[$id]);
       return \Redirect::back();

    }

CodePudding user response:

You can use redirect method, as you have not mentioned the laravel version here some way using laravel 8.x. you can find more on official document

public function destroy($id){
       DB::delete('delete from Rolete where ProdusID = ?' ,[$id]);
       return redirect('/yourpath'); 
       // return back(); return to previous page.
       // return redirect()->route('route name goes here');
       // return redirect()->action([HomeController::class, 'index']);
}
  • Related