0

I am trying to make commenting system for my website but whenever I am submitting my data I am getting this error MethodNotAllowedHttpException in RouteCollection.php line 218:

Here is my code in web.php

<?php


Route::get('/', function () {
return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index');

Route::resource('doomxos','DoomxosController');

here is the code in my model:-

namespace App;

use Illuminate\Database\Eloquent\Model;

class Doomxo extends Model
{
//
 public function userd(){

return $this->belongsTo('App\User');
}
}

here is the code in my blade file

<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"> </script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
 <![endif]-->
 <link rel="stylesheet"  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

 <!-- Latest compiled and minified JavaScript -->
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<div class="row new-post">
    <div class="col-md-6 col-md-offset-3">

        <header><h3>comments</h3></header>
        <form action="route('doomxos.store')" method="post">
        {{csrf_field()}}
            <div class="form-group">
          <textarea class="form-control" name="body" id="new-post"    rows="5" placeholder="Your comment "></textarea>
            </div>
         <button type="submit" class="btn btn-primary">Post comment</button>

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

 @foreach($doomxos as $doomxo)
 <link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css">

 {{$doomxo->created_at}}

 {{$doomxo->body }}


@endforeach


 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
 <script  src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> </script>
 <!-- Include all compiled plugins (below), or include individual files as needed -->
 <script src="js/bootstrap.min.js"></script>
 </body>
 </html>

Here is my code in controller:-

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Doomxo;
use Auth;
use App\User;

class DoomxosController extends Controller
{
/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
    // 
}

/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{
    //
$doomxos = doomxo::all();
return view('doomxos.create', ['doomxos' => $doomxos]);
}

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

 $doomxo= new Doomxo();
    $doomxo->user_id=Auth::userd()->id;
    $doomxo->body=$request->body;
    $request->userd()->doomxos()->save($doomxo);
    return back();
 }

 /**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
 public function show($id)
 {
    //
    $doomxos=doomxo::all();
 return view('doomxos',['doomxos'=>$doomxos]);
 }

 /**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
 public function edit($id)
 {
    //
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request, $id)
{
    //
}

/**
 * Remove the specified resource from storage.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function destroy($id)
{
    //
}

}

Here is the cone in my user.php

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
use Notifiable;

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'name', 'email', 'password',
];

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
 ];

public function comments() {


return $this->hasMany('App\Comment');

}
public function doomxos() {


return $this->hasMany('App\Doomxo');

}

}

Thanks in advance:-)

1 Answer 1

2

Your form action isn't correct, you have:

<form action="route('doomxos.store')" method="post">

You need to use the curly braces as this is a function that needs to run:

<form action="{{ route('doomxos.store') }}" method="post">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.