使用编写的<a href="" in="" laravel

时间:2018-02-15 08:49:57

标签: php html laravel

="" I'm new to Laravel and working on my first project. I'm trying to delete a table row by passing its name through its delete link (a =href) to the route and then to the controller so I can run a mysql query to delete the row.

Here is the code for my table

<table class="table table-bordered table-striped table-highlight">
    <thead>
    <tr bgcolor="#c7c7c7">
        <th>Language</th>
        <th>Description</th>
        <th>Action</th>
    </tr>
    </thead>
    @foreach($getAllangLuages as $list)
    <tr>
        <td>{{$list->language_name}}</td>
        <td>{{$list->description}}</td>
        This is the issue->
        <td><a href="{{url('languages/deleterow')}}?{{$list->language_name}}">Delete</a></td>
    </tr>
    @endforeach
</table>

I'm trying to find the correct way to pass its name to the route and then finally to the controller.

can someone show me what to put in my route::? I'm having problems linking to it

6 个答案:

答案 0 :(得分:1)

如果您的路线有名称,请使用route功能并将 ID 作为参数传递

<a href="{{route('languages.deleterow',$list->id)}}">Delete</a>

否则将 id 作为参数传递给url方法

<a href="{{url('languages/deleterow',$list->id)}}">Delete</a>

答案 1 :(得分:1)

也许我们可以这样做,这就是我在当前项目中所做的事情:

HTML

<a href="groups/delete/{{$groups['id']}}"><button type="button" class="btn btn-info btn-circle " data-toggle="tooltip" data-placement="bottom" title="" data-original-title="delete Groups"><i class="material-icons">remove_red_eye</i></button></a>

我的路线:

Route::get('/groups/delete/{id}','admin\GroupsController@getDeleteUsersGroups');

答案 2 :(得分:1)

您可以使用路由命名进行清理操作。 Laravel Routing

Route::get('languages/deleterow/{name}', function ($name) {
    return App::make('LanguageController')->delete($name);
})->name('deleteLang');

<a href="{{ route('deleteLang', ['name' => $list->language_name]) }}">Delete</a>

答案 3 :(得分:1)

尝试这种方式:

<a href= "{{ url('languages/deleterow',['ID' => $list->language_name]) }}">{{ $list->language_name }}</a>

答案 4 :(得分:0)

试试这个:

<table class="table table-bordered table-striped table-highlight">
    <thead>
    <tr bgcolor="#c7c7c7">
        <th>Language</th>
        <th>Description</th>
        <th>Action</th>
    </tr>
    </thead>
    @foreach($getAllangLuages as $list)
    <tr>
        <td>{{$list->language_name}}</td>
        <td>{{$list->description}}</td>

        // Change This
        <td><a href="{{ route('languages.delete', $list->language_name) }}">Delete</a></td>

    </tr>
    @endforeach
</table>

使用Named routes

Route::GET('/languages/deleterow/{name}', 'YourController@methodName')->name('languages.delete');

答案 5 :(得分:0)

在web.php中:

Route::get('delete/{id}','CategoryController@delete');

在刀片文件中:

<a href = 'delete/{{$getAllangLuages ->id}}'><button type="button">Delete</button></a></td>