为什么我无法传递带有id的数据,当我在delete()上执行代码时为null 我错过了一些帮助我的东西:( 这是我的dataController
<?php
namespace App\Http\Controllers;
use App\topic; //use model topic
use Illuminate\Http\Request;
use Yajra\Datatables\Datatables; //datatable
use App\Http\Requests;
use Carbon\Carbon;
class dataController extends Controller
{
public function listPerintah($list,Request $request)
{
switch ($list) {
case 'delete':
$id = $request['id'];
$topic = topic::find($id);
$topic->delete();
return $topic->name.'Berhasil Dihapus';
break;
default:
return view('datatable.index');
break;
}
}
//dataTable
public function listData(Request $request)
{
$table = topic::select(['topics.*', 'users.name as user_name'])
->join('users', 'users.id', '=', 'topics.user_id')
->get();
$datatables = Datatables::of($table);
if($keyword = $request->get('search')['value'])
{
$datatables->filterColumn('rownum', 'whereRaw', '@rownum + 1 like ?', ["%{$keyword}%"]);
}
return $datatables
->editColumn('user_name', function($table) {
return 'Oleh: '. $table->user_name;
})
->editColumn('created_at', function($table) {
return Carbon::parse($table->created_at)->format('d F Y H:i:s');
})
->addColumn('action',function($table){
return
'<a title="hapus" href="javascript:" onclick="deleteBtn('.$table->id.',\''.$table->title.'\')" class="btn btn-fill btn-xs btn-danger"><span class="fa fa-remove"></span></a>
<a title="ubah" href="'.url("datatable/edit?id=".$table->id).'"
class="btn btn-xs btn-primary"><span class="fa fa-pencil"></span>
</a>' ;
})
->make(true);
}
}
答案 0 :(得分:0)
尝试使用$request->input('id');
代替$request['id']
$request->all()
这用于获取所有传递的输入
如果你想从参数
获取idlike delete / {id} use可以从函数参数
中获取idclass dataController extends Controller
{
public function listPerintah($list,Request $request,$id)