当搜索数据时,Laravel从blade.php调用EDIT和DELETE按钮

时间:2018-04-04 04:42:02

标签: php laravel

我是laravel的新人。我有搜索功能,在搜索数据后我也想要EDIT和DELETE按钮显示。我需要从blade.php调用控制器中的EDIT和DELETE按钮,我不知道该怎么做。

控制器

 public function search(Request $request)
    {
        if ($request->search) {
            $searchs = DB::table('domain')
            ->where('Domain','like','%'. $request->search .'%')
            ->orWhere('Registrar','like','%'. $request->search .'%')
                        ->orWhere('Login_ID','like','%'. $request->search .'%')
            ->orWhere('Password','like','%'. $request->search .'%')
            ->orWhere('New_Mobile','like','%'. $request->search .'%')
            ->orWhere('Mobile','like','%'. $request->search .'%')
            ->orWhere('Email','like','%'. $request->search .'%')
            ->orWhere('Email_Password','like','%'. $request->search .'%')
            ->get();

        if($searchs){
            foreach ($searchs as $key => $search) {
                echo '<tr><td>'. $search->Domain .'</td>
                      <td>'. $search->Registrar .'</td><td>'. $search->Login_ID .'</td><td>'. $search->Password .'</td><td>'. $search->New_Mobile .'</td><td>'. $search->Mobile .'</td><td>'. $search->Email .'</td><td>'. $search->Email_Password .'</td></tr>';
            }
        }
        }
    }

Index.blade.php

@foreach($domain as $row)
   <tr>
    <td>{!!$row->Domain!!}</td>
    <td>{!!$row->Registrar!!}</td>
    <td>{!!$row->Login_ID!!}</td>
    <td>{!!$row->Password!!}</td>
    <td>{!!$row->New_Mobile!!}</td>
    <td>{!!$row->Mobile!!}</td>
    <td>{!!$row->Email!!}</td>
    <td>{!!$row->Email_Password!!}</td>
    <td><a href="{{action('DomainController@edit', $row->No)}}" class="btn btn-warning">Edit</a></td>
    <td>
     <form method="post" class="delete_form" action="{{action('DomainController@destroy', $row->No)}}">
      {{csrf_field()}}
      <input type="hidden" name="_method" value="DELETE" />
      <button type="submit" class="btn btn-danger">Delete</button>
     </form>
    </td>
  </tr>
@endforeach

我的javascript

function search() {
    var search = $('#search').val();
    if (search) {
        $("#table").hide();
        $(".ajaxdata").show();
    } else {
        $("#table").show();
        $(".ajaxdata").hide();
    }
    $.ajax({
        type: "POST",
        url: '{{URL::to("/search")}}',
        data: {
            search: search,
            _token: $('#signup-token').val()
        },
        datatype: 'html',
        success: function(response) {
            console.log(response);
            $("#success").html(response);
        }
    });
}

1 个答案:

答案 0 :(得分:0)

在路线页

Routes::put('/update/{id}, DomainController@edit);

在index.blade.php页面

<td><a href="'.route('/update/'. $row->No).'" class="btn btn-warning">Edit</a></td>

使用不同方法的删除功能相同