Reputation: 183
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';
}
Upvotes: 0
Views: 77
Reputation: 1
i prefer to use this instead of ->with();
public function demo()
{
$listDemos = Demo::all();
return view('backstage.demos',['listDemos'=>$listDemos]);
}
Upvotes: 0
Reputation: 1103
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
Upvotes: 1