dongzhi6927 2017-06-15 05:44
浏览 34
已采纳

保存数据库行的状态

I am newbie to PHP. I have admin panel (Backstage), created on Laravel. On panel shows list of bids (demos) from MySQL table (demos).

I have deleted all html from code below.

Here is code that shows every row from table in demo view:

@foreach($listDemos as $demo)
  {{ $demo->id }}
  {{ $demo->name }}
  {{ $demo->email }}
  {{ $demo->link }}
  {{ $demo->created_at }}
@endforeach

Here is controller for demos

public function demo()
    {
      $listDemos = Demo::all();
      return view('backstage.demos')->with('listDemos', $listDemos);
    }

Here is route for demos:

Route::get('backstage/demos', 'BackstageController@demo');

I have another mysql table (demoStatus) with 2 columns

id and status

The question is how to store status (Decline) in different table (demoStatuswhere id = demo id from demo table and status = button value) by clicking button in demo view:

@foreach($listDemos as $demo)
  {{ $demo->id }}
  {{ $demo->name }}
  {{ $demo->email }}
  {{ $demo->link }}
  {{ $demo->created_at }}

  <form action="" method="post">
     {{ csrf_field() }}
    <button type="submit">Decline</button>
  </form>
@endforeach

CSRF field stored at the head of every page

<meta name="csrf-token" content="{{ csrf_token() }}">

For demoStatus I have another model:

class DemoStatus extends Model
{
    protected $table = 'demosStatus';
    protected $fillable = 'status';
}

and model for demos:

class Demo extends Model
{
    protected $table = 'demos';
}
  • 写回答

2条回答 默认 最新

  • duanqian1888 2017-06-15 05:48
    关注

    Actually you have to send that demo id on from submit. One way of doing that is to use hidden field.

    <form action="some/action/here" method="post">
         {{ csrf_field() }}
        <input type="hidden" name="demo_id" value="{{ $demo->id }}" />
        <button type="submit">Decline</button>
    </form>
    

    The route this post is submitted to. Get this demo id and do whatever you want to do

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?