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,

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮