mercredi 15 août 2018

How to get value of Laravel URL parameter even without embed it in Ajax

I'm using Laravel 5.6, PHP 7.1, XAMPP. I have URL which contain a values from one controller and defined before. My question, how to get the last value in laravel URL without passing a value before. My code below will show the problem as well.

This is my Ajax:

 $(document).ready(function() {

                $('#student_table').DataTable({
                   "processing": true,
                   "serverSide": true,
                   "ajax": "",
                   "columns":[
                       { "data": "group_id" },
                       { "data": "customer_id" },
                       { "data": "customer_id" },
                       { "data": "action", orderable:false, searchable: false},
                       { "data":"checkbox", orderable:false, searchable:false}
                   ]
               });

my route:

Route::get('leads/getdata', 'Controller@getdata')->name('leads.getdata');

Controller.php

 function getdata(Request $request)
    {
        //$id = $request->input('id');

        $students = GroupCustomer::select('id', 'name', 'address')->where('user_id', '=', $id);
        return Datatables::of($students)
            ->addColumn('action', function($student){
                return '<a href="/customers/'.$student->id.'" class="btn btn-xs btn-primary eye" id="'.$student->id.'"><i class="glyphicon glyphicon-eye-open"></i></a><a href="#" class="btn btn-xs btn-danger delete" id="'.$student->id.'"><i class="glyphicon glyphicon-remove"></i></a>';
            })
            ->addColumn('checkbox', '<input type="checkbox" name="student_checkbox[]" class="student_checkbox" value="" />')
            ->rawColumns(['checkbox','action'])
            ->make(true);
    }

The current URL is : http://localhost:8000/leads/6 as I need to get '6' value and pass it to the query to get the name, address of that user. currently, it working without 'where' statement. However, I want to show only the name and address of user_id = '6'.

Is there a way to get this '6' value without change anything in Ajax and route as well ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire