【问题标题】:The GET method is not supported for this route. Supported methods: POST in laravel此路由不支持 GET 方法。支持的方法:laravel 中的 POST
【发布时间】:2020-05-22 15:36:04
【问题描述】:

我正在尝试在验证后添加帖子,并获取发布帖子的医生的姓名并将其添加到博客中。 当我单击提交添加帖子时,我收到此错误:

The GET method is not supported for this route. Supported methods: POST.

但是当我检查数据库时,我发现了帖子。

这是控制器后控制器:

 public function add()
       {


        $blog= new blog;

        $blog-> title = request('title');
        $blog ->body = request('description');
        $blog->author_id=request('articlemed');
        $blog ->image = request('photo');
        $blog-> save();
        return view ('index') ; 


    }

这是形式:

     <form action="{{ url('/add') }}" method="POST" enctype="multipart/form-data">
     @csrf
     <label for="">Titre de l'article</label>
     <input type="text" class="form-control" name="title" id=""  placeholder="Titre de l'article">
     <label for=""> Description de l'article</label> </br>
     <textarea name="description" id="" cols="63" rows="20"></textarea> 
     <label for="">Image pour l'article</label>
     <input type="file" name="photo" class="form-control" id=""  placeholder="Titre de l'article">
     <input type="hidden"  class="form-control" name="articlemed" value="{{$med->ID}}" />
     <button type="submit" class="btn btn-primary"> Ajouter l'article </button>
     </form>

这是 web.php :

Route::post('/add', 'postcontroller@add');

这也是认证的控制器:

  public function authentification (Request $request) 
    { 
        $this->validate($request, [

        'email' => 'required',
        'mdp'=> 'required'
    ]);

    $logmedecin=doc::orderBy('created_at','desc')->get() ;
    $rdv=rendezvous::get(); 

    foreach ($logmedecin as $log ) 
    {
        if (( $log->Login== $request->input('email') ) && ( $log->Password== $request->input('mdp') ))
        {
            return view ('/bienvenu',['med'=>$log] ,['pat'=>$rdv] );
        }
    }
    return back()->withErrors([
        'message'=> 'Emails or password not correct!'
        ]) ; 
}

和认证的web.php:

Route::post('/bienvenu','doctor@authentification')->name('aziz');

【问题讨论】:

  • 尝试像Route::get('/add', 'postcontroller@add');那样添加一条获取路线@

标签: laravel forms


【解决方案1】:

所以问题是我没有使用帖子和用户之间的关系(一对多) 所以我只是将这个添加到我的 Post 模型中:

  public function user()
    {
        return $this->belongsTo('App\doc');
    }

我将它添加到用户模型中:

 public function article()
    {
        return $this->hasMany('App\blog');
    }

【讨论】:

    猜你喜欢
    • 2021-04-11
    • 2021-08-05
    • 2020-06-05
    • 2020-03-21
    • 2021-01-10
    • 2020-04-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多