douruoshen1449 2014-11-30 08:04
浏览 52

Laravel从数据库中删除行并列出剩余的行

I have a laravel web application and i would like to delete a row from my formdata table and after successful deletion i want to display remaining table rows with an deleted flash message.

please take a look in my code,

Routes.php

Route::get('manage-forms',array('as'=>'manage_forms','uses'=>'Nri@manage_forms')); 

this route is listing the table rows(datas).

Route::get('delete/{id}',array('as'=>'delete_formdata','uses'=>'Nri@delete_form'));

this route is deleting existing one row and sending flash message to the above route.

Controller ==>

public function manage_forms()
{
    $form_data=Formdata::all();
    return View::make('manage_forms')->with('form_array',$form_data);
}

public function delete_form($id)
{

    $deleted=Formdata::find($id);
    $deleted->delete();

    return View::make('manage_forms')->with('message','the Data is deleted');
}

View Registered Form details

 <h2>Registered Form details</h2>

 @if(Session::has('message'))
 <p>{{ Session::get('message') }}</p>
 @endif
 <table border="0">
<tr>
<td>Name</td>
<td>Mobile</td>

</tr>
@foreach($form_array as $form_view)
<tr>
    <td>
        <input type="hidden" name="id" value="{{$form_view->id}}">
        <input type="text" name="name" value="{{$form_view->name}}"/>
    </td>

    <td>{{$form_view->mobile}}</td>
    <td>{{HTML::linkRoute('edit_formdata','Edit',array($form_view->id))}}</td>
    <td>{{HTML::linkRoute('view_formdata','View ',array($form_view->id))}}</td>
    <td>{{HTML::linkRoute('delete_formdata','Delete ',array($form_view->id))}}</td>
</tr>
@endforeach
</table>


 <h2>{{HTML::linkRoute('test_session','Home')}}</h2>

Normally i points to manage-forms route, it displaying correct data from database & working fine.

but after deletion the browser showing me to error like below,

 Undefined variable: form_array (View: F:\xampp\htdocs\laravel2\app\views\manage_forms.blade.php)

it does not redirected to manage-forms route,

Anybody please help me,

Thanks

  • 写回答

1条回答 默认 最新

  • douweilaton2762 2014-11-30 08:13
    关注

    Just Use the return Redirect::to('manage-forms') to solve this issue,

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口