mercredi 27 décembre 2017

How can I add an external JS file to my laravel controller file

I'm new to Laravel and I wrote a piece of code to extract data from a database and display it in a tabular form using the Ajax.

Now I want to add 'onclick' function to the result. I've tried importing the external JS file but can't seem to get it right. Here's my code

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;

class courseController extends Controller
{
 /**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('auth');
}


/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
    return view('course_registration');
}
public function search(Request $request)
{
    if($request->ajax())
    {
        $output="";

       $student=DB::table('dataentries')->where('ID_number','LIKE','%'.$request->search.'%')
                                        ->orWhere('name','LIKE','%'.$request->search.'%')->get();

        if($student)
        {
            foreach($student as $key => $student){
                $output.='<tr id="copy" onclick=\'copy()\'>'.
                        '<td>'.$student->ID_number.'</td>'.
                        '<td>'.$student->name.'</td>'.
                        '</tr>';

            }
            return Response($output);
        }
        else
        {

        }
    }
}

}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2BNEdDe
via IFTTT

Aucun commentaire:

Enregistrer un commentaire