laravel此路线不支持PUT方法。支持的方法:GET,HEAD

时间:2020-02-12 17:12:04

标签: laravel post

我有问题。我想从我的发布表中创建公告 通过制作2种组合形式,但是我不这样做,因为我对laravel是陌生的,这就是我所拥有的

刀片

<form action="{{route('superadminpage.admin_announce.admin_view_announce',$announces->id)}}" method="POST" enctype="multipart/form-data">


                <div class="container">
                    <div class="jumnbotron"> 
                        <h1>  </h1>
                    <br>
                    <div class="container">
                        <div class="jumnbotron"> 
                            <h1>  Notification Announcement </h1>
                        <br>

                        <form method="POST" action="{{action('AdminController@store',$announces->id)}}">
                            {{csrf_field() }}

                        <div class="card">
                            <div class="card-body">
                                <input type="hidden" name="_method" value="PUT" />
                                 <input  type="text" name="title" class="form-control" value="{{$announces->departments->department}} "> <h3>  </h3>

                            <input type="hidden" name="_method" value="PUT" />
                                <input  type="text" name="title" class="form-control" value="{{ $announces->Title}}"> <br>

                                <input type="hidden" name="_method" value="PUT" />
                             <input  type="text" name="title" class="form-control" value="{{ $announces->Content}}">    <br>





                            </div>
                            <input type="submit" name="submit" class="btn btn-primary" value="notify"/>


                          </div> 

                        </form>

                          <a href="{{action('AdminController@edit',['id' =>$announces->id])}} " class="btn btn-info">edit </a>



                    </div>
                </div>
            </form>

控制器

public function view($id)
{

    $announces = Post::find($id);
    return view('superadminpage.admin_announce.admin_view_announce',compact('announces', 'id'));
}

/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{
    //
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
    $data = request()->validate([

        'department_id' => ['required', 'string', 'max:255'],
        'Title' => ['required', 'string', 'max:255'],
        'Content' => ['required', 'string', 'max:255'],


        ]);

        $data = Announcement::create([

            'department_id' => $data['department_id'],
            'Title' => $data['Title'],
            'Content' => $data['Content'],

        ]);




        return redirect('admin_update')->with('success', 'Events has been added');
}

和路线

    Route::get('/admin_update', 'AdminController@index');
Route::get('/admin_view_announce/{id}', 'AdminController@view')->name('superadminpage.admin_announce.admin_view_announce');
Route::put('/admin_view_announce', 'AdminController@store');
Route::get('/admin_announce_create/{id}', 'AdminController@show');
Route::get('/admin_announce_editform/{id}', 'AdminController@edit')->name('superadminpage.admin_announce.admin_announce_editform');
Route::put('/admin_announce_editform/{id}', 'AdminController@update')->name('superadminpage.admin_announce.admin_announce_editform');

注意:(我不是在说雄辩,我只是从刀片中显示的“发布到公告”中获取数据)

0 个答案:

没有答案