【问题标题】:Why my edit page didn't work in Laravel? I used vue.js为什么我的编辑页面在 Laravel 中不起作用?我使用了 vue.js
【发布时间】:2020-06-14 08:26:09
【问题描述】:

基本上,我正在做一个仪表板来查看详细信息。如果用户想要编辑他们的详细信息。他们应该点击编辑按钮来编辑它。如果我点击编辑按钮它没有响应任何东西。现在编辑不起作用。我找不到问题。我在这里附上我的代码。

index.blade.php

@extends('layouts.main')

@section('content')
    <div class="justpaddingside" role="main" >
        <div class="row w-100 Bfont">
            <div class="col-xs-12">
                <div class="havence-content">
                    <div class="havence-content-body">
                        <div class="dashboardbg">
                            <div class="x_title" >
                                <img src="https://img.icons8.com/bubbles/50/000000/important-mail.png" class="rounded float-left" >  
                                <h2 class="p-3 font-weight-bold">Email Reminder Dashboard</h2> 
                                <h4 class="text-right">{{date('d-m-Y')}}</h4>
                                <h5 class="text-right">{{date('H:i:s')}}</h5>
                            </div>
                            <div class="col-md-12 text-right"> 
                                <a href="mail" class="btn btn-danger badge-pill"  > Create New Template </a>
                            </div>
                        </div>
                        <div class="contentbg p-5">
                            <div class="row w-100">
                                <div class="havence-content-datatable table-responsive">
                                <table class="table table-hover table-info"  cellpadding="0" cellspacing="0" border="0">
                                    <thead class="">
                                        <tr>
                                            <th scope="col">ID</th>
                                            <th scope="col">Subject</th>
                                            <th scope="col">Message</th>
                                            <th scope="col">Condition</th>
                                            <th scope="col">Module Name</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach ($mailTemplates as $mailTemplate)
                                        <tr>
                                            <th>{{$mailTemplate->id}}</th>
                                            <th>{{$mailTemplate->subject}} </th>
                                            <th>{{$mailTemplate->message}} </th>
                                            <th>{{$mailTemplate->condition_id}} </th>
                                            <th>{{$mailTemplate->mod_name}}</th>

                                            <td class="text-right">
                                                <a href='edit/{id}' class="btn btn-danger badge-pill" style="width:80px" >EDIT </a>
                                                <form action="{{ route('havence.automail.delete', $mailTemplate) }}" method="POST">
                                                    @csrf
                                                    @method('DELETE')
                                                    <button type="submit" class="btn btn-danger">Delete</button>
                                                </form>
                                            </td>

                                        </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {!! Form::open(['method'=>'post', 'id'=> 'delete-frm']) !!}
    @method('DELETE')
    @csrf
    {!! Form::close() !!}


</div>


@endsection

@push('stylesheets')
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.16/datatables.min.css"/>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/css/select2.min.css">
@endpush

@push('scripts')
    <script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.16/datatables.min.js"></script>
    <script src="https://unpkg.com/sweetalert2@7.19.3/dist/sweetalert2.all.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.min.js"></script>
@endpush

@section('page-js')
    <script>


    </script>
@endsection

AutoMailController.php

 public function edit($id)
    {
        $mailTemplates=AutoEmailTemplate::find($id);
        return view('havence.automail.edit')->with('mailTemplates', $mailTemplates);
    }

web.php

Route::get('api/email/create', ['as' => 'email.create', 'uses' => 'Havence\AutoMailController@create']);
    Route::get('automail/mail', 'Havence\AutoMailController@mail');
    Route::get('automail/index',['as'=>'email.index','uses' => 'Havence\AutoMailController@index']);
    Route::get('automail/edit/{id}',['as'=>'email.edit','uses' => 'Havence\AutoMailController@edit']);
    Route::get('automail/delete',['as'=>'email.delete','uses' => 'Havence\AutoMailController@destroy']);

【问题讨论】:

  • 没有错误?控制台有错误吗?

标签: javascript php laravel vue.js


【解决方案1】:

尝试使用:

<a href='{{ route("email.edit",["id"=>$mailTemplate->id]) }}' class="btn btn-danger badge-pill" style="width:80px" >EDIT </a>

【讨论】:

  • 它显示的视图 [havence.automail.edit] 未找到。我认为我的路线给出问题是什么? @IIIya
【解决方案2】:

您没有从 href 和用户 laravel 字符串插值“{{ $variable }}”传递 id。

<a href='edit/{{$mailTemplate->id}}' class="btn btn-danger badge-pill" style="width:80px" >EDIT </a>

如果您想在另一个选项卡中打开路线,请在您的“a”标签中添加 target="_blank"。

<a href='edit/{{$mailTemplate->id}}' target='_blank' class="btn btn-danger badge-pill" style="width:80px" >EDIT </a>

【讨论】:

  • 它显示的视图 [havence.automail.edit] 未找到。
  • 我的路线有问题吗?
  • @NavanithaMoorthy 检查刀片文件是否存在。
  • 我的刀片存在
  • 但不知道如何连接@Poldo
【解决方案3】:

更换怎么样:

<a href='edit/{id}' class="btn btn-danger badge-pill" style="width:80px" >EDIT </a>

与:

<a href={{'edit/'.$mailTemplate->id}} class="btn btn-danger badge-pill" style="width:80px" >EDIT </a>

【讨论】:

  • 我尝试使用该方法。它显示 InvalidArgumentException 抛出消息“未找到查看 [havence.automail.edit]”。 @Jmielh
  • 我的路线有问题吗? @Jmielh
  • 您的 VIEW 文件有问题,而不是路线。按照要求创建视图,或者如果您已经创建了视图,则将其移动到正确的文件夹中。
  • 那么,现在我需要创建一个视图文件是吗?
  • 是的,您需要创建一个视图文件以在表单中显示编辑选项,然后在控制器中创建一个函数来更新信息。我不知道您正在编辑什么或可以编辑哪些字段,但您肯定需要更新数据库中的数据。
猜你喜欢
  • 2020-12-27
  • 2020-10-09
  • 1970-01-01
  • 2020-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-13
相关资源
最近更新 更多